本文整理汇总了Golang中github.com/cloudfoundry/bosh-agent/logger.NewLogger函数的典型用法代码示例。如果您正苦于以下问题:Golang NewLogger函数的具体用法?Golang NewLogger怎么用?Golang NewLogger使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewLogger函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: init
func init() {
Describe("renderedJobApplier", func() {
var (
jobsBc *fakebc.FakeBundleCollection
jobSupervisor *fakejobsuper.FakeJobSupervisor
packageApplierProvider *fakepa.FakePackageApplierProvider
blobstore *fakeblob.FakeBlobstore
compressor *fakecmd.FakeCompressor
fs *fakesys.FakeFileSystem
applier JobApplier
)
BeforeEach(func() {
jobsBc = fakebc.NewFakeBundleCollection()
jobSupervisor = fakejobsuper.NewFakeJobSupervisor()
packageApplierProvider = fakepa.NewFakePackageApplierProvider()
blobstore = fakeblob.NewFakeBlobstore()
fs = fakesys.NewFakeFileSystem()
compressor = fakecmd.NewFakeCompressor()
logger := boshlog.NewLogger(boshlog.LevelNone)
applier = NewRenderedJobApplier(
jobsBc,
jobSupervisor,
packageApplierProvider,
blobstore,
compressor,
fs,
logger,
)
})
Describe("Prepare & Apply", func() {
var (
job models.Job
bundle *fakebc.FakeBundle
)
BeforeEach(func() {
job, bundle = buildJob(jobsBc)
})
ItInstallsJob := func(act func() error) {
It("returns error when installing job fails", func() {
bundle.InstallError = errors.New("fake-install-error")
err := act()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-install-error"))
})
It("downloads and later cleans up downloaded job template blob", func() {
blobstore.GetFileName = "/fake-blobstore-file-name"
err := act()
Expect(err).ToNot(HaveOccurred())
Expect(blobstore.GetBlobIDs[0]).To(Equal("fake-blobstore-id"))
Expect(blobstore.GetFingerprints[0]).To(Equal("fake-blob-sha1"))
// downloaded file is cleaned up
Expect(blobstore.CleanUpFileName).To(Equal("/fake-blobstore-file-name"))
})
It("returns error when downloading job template blob fails", func() {
blobstore.GetError = errors.New("fake-get-error")
err := act()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-get-error"))
})
It("decompresses job template blob to tmp path and later cleans it up", func() {
fs.TempDirDir = "/fake-tmp-dir"
blobstore.GetFileName = "/fake-blobstore-file-name"
var tmpDirExistsBeforeInstall bool
bundle.InstallCallBack = func() {
tmpDirExistsBeforeInstall = true
}
err := act()
Expect(err).ToNot(HaveOccurred())
Expect(compressor.DecompressFileToDirTarballPaths[0]).To(Equal("/fake-blobstore-file-name"))
Expect(compressor.DecompressFileToDirDirs[0]).To(Equal("/fake-tmp-dir"))
// tmp dir exists before bundle install
Expect(tmpDirExistsBeforeInstall).To(BeTrue())
// tmp dir is cleaned up after install
Expect(fs.FileExists(fs.TempDirDir)).To(BeFalse())
})
It("returns error when temporary directory creation fails", func() {
fs.TempDirError = errors.New("fake-filesystem-tempdir-error")
err := act()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-filesystem-tempdir-error"))
})
//.........这里部分代码省略.........
开发者ID:keaty,项目名称:bosh-provisioner,代码行数:101,代码来源:rendered_job_applier_test.go
示例2:
Expect(err).ToNot(HaveOccurred())
defer file.Close()
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
io.Copy(w, file)
Expect(r.Method).To(Equal("GET"))
Expect(r.URL.Path).To(Equal("/_status2"))
Expect(r.URL.Query().Get("format")).To(Equal("xml"))
})
ts := httptest.NewServer(handler)
defer ts.Close()
logger := boshlog.NewLogger(boshlog.LevelNone)
client := NewHTTPClient(
ts.Listener.Addr().String(),
"fake-user",
"fake-pass",
http.DefaultClient,
1*time.Millisecond,
logger,
)
status, err := client.Status()
Expect(err).ToNot(HaveOccurred())
expectedServices := []Service{
Service{Monitored: true, Status: "running"},
Service{Monitored: false, Status: "unknown"},
开发者ID:keaty,项目名称:bosh-provisioner,代码行数:31,代码来源:status_test.go
示例3: init
func init() {
Describe("concreteManagerProvider", func() {
Describe("NewManager", func() {
It("returns manager with tasks.json as its tasks path", func() {
logger := boshlog.NewLogger(boshlog.LevelNone)
fs := fakesys.NewFakeFileSystem()
taskInfo := boshtask.TaskInfo{
TaskID: "fake-task-id",
Method: "fake-method",
Payload: []byte("fake-payload"),
}
manager := boshtask.NewManagerProvider().NewManager(logger, fs, "/dir/path")
err := manager.AddTaskInfo(taskInfo)
Expect(err).ToNot(HaveOccurred())
// Check expected file location with another manager
otherManager := boshtask.NewManager(logger, fs, "/dir/path/tasks.json")
taskInfos, err := otherManager.GetTaskInfos()
Expect(err).ToNot(HaveOccurred())
Expect(taskInfos).To(Equal([]boshtask.TaskInfo{taskInfo}))
})
})
})
Describe("concreteManager", func() {
var (
logger boshlog.Logger
fs *fakesys.FakeFileSystem
manager boshtask.Manager
)
BeforeEach(func() {
logger = boshlog.NewLogger(boshlog.LevelNone)
fs = fakesys.NewFakeFileSystem()
manager = boshtask.NewManager(logger, fs, "/dir/path")
})
Describe("GetTaskInfos", func() {
It("can load multiple tasks", func() {
err := manager.AddTaskInfo(boshtask.TaskInfo{
TaskID: "fake-task-id-1",
Method: "fake-method-1",
Payload: []byte("fake-payload-1"),
})
Expect(err).ToNot(HaveOccurred())
err = manager.AddTaskInfo(boshtask.TaskInfo{
TaskID: "fake-task-id-2",
Method: "fake-method-2",
Payload: []byte("fake-payload-2"),
})
Expect(err).ToNot(HaveOccurred())
// Make sure we are not getting cached copy of taskInfos
reloadedManager := boshtask.NewManager(logger, fs, "/dir/path")
taskInfos, err := reloadedManager.GetTaskInfos()
Expect(err).ToNot(HaveOccurred())
Expect(taskInfos).To(Equal([]boshtask.TaskInfo{
boshtask.TaskInfo{
TaskID: "fake-task-id-1",
Method: "fake-method-1",
Payload: []byte("fake-payload-1"),
},
boshtask.TaskInfo{
TaskID: "fake-task-id-2",
Method: "fake-method-2",
Payload: []byte("fake-payload-2"),
},
}))
})
It("succeeds when there is no tasks (file is not present)", func() {
taskInfos, err := manager.GetTaskInfos()
Expect(err).ToNot(HaveOccurred())
Expect(len(taskInfos)).To(Equal(0))
})
It("returns an error when failing to load tasks from the file that exists", func() {
err := manager.AddTaskInfo(boshtask.TaskInfo{
TaskID: "fake-task-id-2",
Method: "fake-method-2",
Payload: []byte("fake-payload-2"),
})
Expect(err).ToNot(HaveOccurred())
fs.ReadFileError = errors.New("fake-read-error")
_, err = manager.GetTaskInfos()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-read-error"))
})
})
Describe("AddTaskInfo", func() {
It("can add multiple tasks", func() {
err := manager.AddTaskInfo(boshtask.TaskInfo{
//.........这里部分代码省略.........
开发者ID:keaty,项目名称:bosh-provisioner,代码行数:101,代码来源:concrete_manager_test.go
示例4: init
func init() {
Describe("concretePackageApplier", func() {
var (
packagesBc *fakebc.FakeBundleCollection
blobstore *fakeblob.FakeBlobstore
compressor *fakecmd.FakeCompressor
fs *fakesys.FakeFileSystem
logger boshlog.Logger
applier PackageApplier
)
BeforeEach(func() {
packagesBc = fakebc.NewFakeBundleCollection()
blobstore = fakeblob.NewFakeBlobstore()
compressor = fakecmd.NewFakeCompressor()
fs = fakesys.NewFakeFileSystem()
logger = boshlog.NewLogger(boshlog.LevelNone)
applier = NewConcretePackageApplier(packagesBc, true, blobstore, compressor, fs, logger)
})
Describe("Prepare & Apply", func() {
var (
pkg models.Package
bundle *fakebc.FakeBundle
)
BeforeEach(func() {
pkg, bundle = buildPkg(packagesBc)
})
ItInstallsPkg := func(act func() error) {
It("returns error when installing package fails", func() {
bundle.InstallError = errors.New("fake-install-error")
err := act()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-install-error"))
})
It("downloads and later cleans up downloaded package blob", func() {
blobstore.GetFileName = "/fake-blobstore-file-name"
err := act()
Expect(err).ToNot(HaveOccurred())
Expect(blobstore.GetBlobIDs[0]).To(Equal("fake-blobstore-id"))
Expect(blobstore.GetFingerprints[0]).To(Equal("fake-blob-sha1"))
// downloaded file is cleaned up
Expect(blobstore.CleanUpFileName).To(Equal("/fake-blobstore-file-name"))
})
It("returns error when downloading package blob fails", func() {
blobstore.GetError = errors.New("fake-get-error")
err := act()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-get-error"))
})
It("decompresses package blob to tmp path and later cleans it up", func() {
fs.TempDirDir = "/fake-tmp-dir"
blobstore.GetFileName = "/fake-blobstore-file-name"
var tmpDirExistsBeforeInstall bool
bundle.InstallCallBack = func() {
tmpDirExistsBeforeInstall = true
}
err := act()
Expect(err).ToNot(HaveOccurred())
Expect(compressor.DecompressFileToDirTarballPaths[0]).To(Equal("/fake-blobstore-file-name"))
Expect(compressor.DecompressFileToDirDirs[0]).To(Equal("/fake-tmp-dir"))
// tmp dir exists before bundle install
Expect(tmpDirExistsBeforeInstall).To(BeTrue())
// tmp dir is cleaned up after install
Expect(fs.FileExists(fs.TempDirDir)).To(BeFalse())
})
It("returns error when temporary directory creation fails", func() {
fs.TempDirError = errors.New("fake-filesystem-tempdir-error")
err := act()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-filesystem-tempdir-error"))
})
It("returns error when decompressing package blob fails", func() {
compressor.DecompressFileToDirErr = errors.New("fake-decompress-error")
err := act()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-decompress-error"))
})
It("installs bundle from decompressed tmp path of a package blob", func() {
fs.TempDirDir = "/fake-tmp-dir"
//.........这里部分代码省略.........
开发者ID:keaty,项目名称:bosh-provisioner,代码行数:101,代码来源:concrete_package_applier_test.go
示例5: init
func init() {
Describe("concreteBuilder", func() {
var (
settingsService *fakesettings.FakeSettingsService
builder Builder
)
BeforeEach(func() {
logger := boshlog.NewLogger(boshlog.LevelNone)
settingsService = &fakesettings.FakeSettingsService{}
builder = NewBuilder(settingsService, logger)
})
Describe("Build", func() {
It("builds alert with id, severity and other monit related info", func() {
builtAlert, err := builder.Build(buildMonitAlert())
Expect(err).ToNot(HaveOccurred())
Expect(builtAlert).To(Equal(Alert{
ID: "some random id",
Severity: SeverityAlert,
Title: "nats - does not exist - restart",
Summary: "process is not running",
CreatedAt: 1306076861,
}))
})
It("sets the severity based on event", func() {
alerts := map[string]SeverityLevel{
"action done": SeverityIgnored,
"Action done": SeverityIgnored,
"action Done": SeverityIgnored,
}
for event, expectedSeverity := range alerts {
inputAlert := buildMonitAlert()
inputAlert.Event = event
builtAlert, _ := builder.Build(inputAlert)
Expect(builtAlert.Severity).To(Equal(expectedSeverity))
}
})
It("sets default severity to critical", func() {
inputAlert := buildMonitAlert()
inputAlert.Event = "some unknown event"
builtAlert, _ := builder.Build(inputAlert)
Expect(builtAlert.Severity).To(Equal(SeverityCritical))
})
It("sets created at", func() {
inputAlert := buildMonitAlert()
inputAlert.Date = "Thu, 02 May 2013 20:07:41 +0500"
builtAlert, _ := builder.Build(inputAlert)
Expect(int(builtAlert.CreatedAt)).To(Equal(int(1367507261)))
})
It("defaults created at to now on parse error", func() {
inputAlert := buildMonitAlert()
inputAlert.Date = "Thu, 02 May 2013 20:07:0"
builtAlert, _ := builder.Build(inputAlert)
createdAt := time.Unix(builtAlert.CreatedAt, 0)
assert.WithinDuration(GinkgoT(), time.Now(), createdAt, 1*time.Second)
})
It("sets the title with ips", func() {
inputAlert := buildMonitAlert()
settingsService.Settings.Networks = boshsettings.Networks{
"fake-net1": boshsettings.Network{IP: "192.168.0.1"},
"fake-net2": boshsettings.Network{IP: "10.0.0.1"},
}
builtAlert, _ := builder.Build(inputAlert)
Expect(builtAlert.Title).To(Equal("nats (10.0.0.1, 192.168.0.1) - does not exist - restart"))
})
})
})
}
开发者ID:keaty,项目名称:bosh-provisioner,代码行数:79,代码来源:concrete_builder_test.go
示例6: createSfdiskPartitionerForTests
func createSfdiskPartitionerForTests(runner *fakesys.FakeCmdRunner) (partitioner Partitioner) {
logger := boshlog.NewLogger(boshlog.LevelNone)
partitioner = NewSfdiskPartitioner(logger, runner)
return
}
开发者ID:keaty,项目名称:bosh-provisioner,代码行数:5,代码来源:sfdisk_partitioner_test.go
示例7: init
func init() {
Describe("provider", func() {
var (
platform *fakeplatform.FakePlatform
client *fakemonit.FakeMonitClient
logger boshlog.Logger
dirProvider boshdir.DirectoriesProvider
jobFailuresServerPort int
handler *fakembus.FakeHandler
provider Provider
)
BeforeEach(func() {
platform = fakeplatform.NewFakePlatform()
client = fakemonit.NewFakeMonitClient()
logger = boshlog.NewLogger(boshlog.LevelNone)
dirProvider = boshdir.NewDirectoriesProvider("/fake-base-dir")
jobFailuresServerPort = 2825
handler = &fakembus.FakeHandler{}
provider = NewProvider(
platform,
client,
logger,
dirProvider,
handler,
)
})
It("provides a monit job supervisor", func() {
actualSupervisor, err := provider.Get("monit")
Expect(err).ToNot(HaveOccurred())
expectedSupervisor := NewMonitJobSupervisor(
platform.Fs,
platform.Runner,
client,
logger,
dirProvider,
jobFailuresServerPort,
MonitReloadOptions{
MaxTries: 3,
MaxCheckTries: 6,
DelayBetweenCheckTries: 5 * time.Second,
},
)
Expect(actualSupervisor).To(Equal(expectedSupervisor))
})
It("provides a dummy job supervisor", func() {
actualSupervisor, err := provider.Get("dummy")
Expect(err).ToNot(HaveOccurred())
expectedSupervisor := NewDummyJobSupervisor()
Expect(actualSupervisor).To(Equal(expectedSupervisor))
})
It("provides a dummy nats job supervisor", func() {
actualSupervisor, err := provider.Get("dummy-nats")
Expect(err).NotTo(HaveOccurred())
expectedSupervisor := NewDummyNatsJobSupervisor(handler)
Expect(actualSupervisor).To(Equal(expectedSupervisor))
})
It("returns an error when the supervisor is not found", func() {
_, err := provider.Get("does-not-exist")
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("does-not-exist could not be found"))
})
})
}
开发者ID:keaty,项目名称:bosh-provisioner,代码行数:72,代码来源:provider_test.go
示例8: init
func init() {
Describe("asyncTaskService", func() {
var (
uuidGen *fakeuuid.FakeGenerator
service Service
)
BeforeEach(func() {
uuidGen = &fakeuuid.FakeGenerator{}
service = NewAsyncTaskService(uuidGen, boshlog.NewLogger(boshlog.LevelNone))
})
Describe("StartTask", func() {
startAndWaitForTaskCompletion := func(task Task) Task {
service.StartTask(task)
for task.State == TaskStateRunning {
time.Sleep(time.Nanosecond)
task, _ = service.FindTaskWithID(task.ID)
}
return task
}
It("sets return value on a successful task", func() {
runFunc := func() (interface{}, error) { return 123, nil }
task, err := service.CreateTask(runFunc, nil, nil)
Expect(err).ToNot(HaveOccurred())
task = startAndWaitForTaskCompletion(task)
Expect(task.State).To(BeEquivalentTo(TaskStateDone))
Expect(task.Value).To(Equal(123))
Expect(task.Error).To(BeNil())
})
It("sets task error on a failing task", func() {
err := errors.New("fake-error")
runFunc := func() (interface{}, error) { return nil, err }
task, createErr := service.CreateTask(runFunc, nil, nil)
Expect(createErr).ToNot(HaveOccurred())
task = startAndWaitForTaskCompletion(task)
Expect(task.State).To(BeEquivalentTo(TaskStateFailed))
Expect(task.Value).To(BeNil())
Expect(task.Error).To(Equal(err))
})
Describe("CreateTask", func() {
It("can run task created with CreateTask which does not have end func", func() {
ranFunc := false
runFunc := func() (interface{}, error) { ranFunc = true; return nil, nil }
task, err := service.CreateTask(runFunc, nil, nil)
Expect(err).ToNot(HaveOccurred())
startAndWaitForTaskCompletion(task)
Expect(ranFunc).To(BeTrue())
})
It("can run task created with CreateTask which has end func", func() {
ranFunc := false
runFunc := func() (interface{}, error) { ranFunc = true; return nil, nil }
ranEndFunc := false
endFunc := func(Task) { ranEndFunc = true }
task, err := service.CreateTask(runFunc, nil, endFunc)
Expect(err).ToNot(HaveOccurred())
startAndWaitForTaskCompletion(task)
Expect(ranFunc).To(BeTrue())
Expect(ranEndFunc).To(BeTrue())
})
It("returns an error if generate uuid fails", func() {
uuidGen.GenerateError = errors.New("fake-generate-uuid-error")
_, err := service.CreateTask(nil, nil, nil)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-generate-uuid-error"))
})
})
Describe("CreateTaskWithID", func() {
It("can run task created with CreateTaskWithID which does not have end func", func() {
ranFunc := false
runFunc := func() (interface{}, error) { ranFunc = true; return nil, nil }
task := service.CreateTaskWithID("fake-task-id", runFunc, nil, nil)
startAndWaitForTaskCompletion(task)
Expect(ranFunc).To(BeTrue())
})
It("can run task created with CreateTaskWithID which has end func", func() {
ranFunc := false
runFunc := func() (interface{}, error) { ranFunc = true; return nil, nil }
ranEndFunc := false
endFunc := func(Task) { ranEndFunc = true }
//.........这里部分代码省略.........
开发者ID:keaty,项目名称:bosh-provisioner,代码行数:101,代码来源:async_task_service_test.go
示例9: init
func init() {
Describe("execCmdRunner", func() {
var (
runner CmdRunner
)
BeforeEach(func() {
runner = NewExecCmdRunner(boshlog.NewLogger(boshlog.LevelNone))
})
Describe("RunComplexCommand", func() {
It("run complex command with working directory", func() {
cmd := Command{
Name: "ls",
Args: []string{"-l"},
WorkingDir: "..",
}
stdout, stderr, status, err := runner.RunComplexCommand(cmd)
Expect(err).ToNot(HaveOccurred())
Expect(stdout).To(ContainSubstring("README.md"))
Expect(stdout).To(ContainSubstring("total"))
Expect(stderr).To(BeEmpty())
Expect(status).To(Equal(0))
})
It("run complex command with env", func() {
cmd := Command{
Name: "env",
Env: map[string]string{
"FOO": "BAR",
},
}
stdout, stderr, status, err := runner.RunComplexCommand(cmd)
Expect(err).ToNot(HaveOccurred())
Expect(stdout).To(ContainSubstring("FOO=BAR"))
Expect(stdout).To(ContainSubstring("PATH="))
Expect(stderr).To(BeEmpty())
Expect(status).To(Equal(0))
})
It("prints stdout/stderr to provided I/O object", func() {
fs := fakesys.NewFakeFileSystem()
stdoutFile, err := fs.OpenFile("/fake-stdout-path", os.O_RDWR, os.FileMode(0644))
Expect(err).ToNot(HaveOccurred())
stderrFile, err := fs.OpenFile("/fake-stderr-path", os.O_RDWR, os.FileMode(0644))
Expect(err).ToNot(HaveOccurred())
cmd := Command{
Name: "bash",
Args: []string{"-c", "echo fake-out >&1; echo fake-err >&2"},
Stdout: stdoutFile,
Stderr: stderrFile,
}
stdout, stderr, status, err := runner.RunComplexCommand(cmd)
Expect(err).ToNot(HaveOccurred())
Expect(stdout).To(BeEmpty())
Expect(stderr).To(BeEmpty())
Expect(status).To(Equal(0))
stdoutContents := make([]byte, 1024)
_, err = stdoutFile.Read(stdoutContents)
Expect(err).ToNot(HaveOccurred())
Expect(string(stdoutContents)).To(ContainSubstring("fake-out"))
stderrContents := make([]byte, 1024)
_, err = stderrFile.Read(stderrContents)
Expect(err).ToNot(HaveOccurred())
Expect(string(stderrContents)).To(ContainSubstring("fake-err"))
})
})
Describe("RunComplexCommandAsync", func() {
It("populates stdout and stderr", func() {
cmd := Command{Name: "ls"}
process, err := runner.RunComplexCommandAsync(cmd)
Expect(err).ToNot(HaveOccurred())
result := <-process.Wait()
Expect(result.Error).ToNot(HaveOccurred())
Expect(result.ExitStatus).To(Equal(0))
})
It("populates stdout and stderr", func() {
cmd := Command{Name: "bash", Args: []string{"-c", "echo stdout >&1; echo stderr >&2"}}
process, err := runner.RunComplexCommandAsync(cmd)
Expect(err).ToNot(HaveOccurred())
result := <-process.Wait()
Expect(result.Error).ToNot(HaveOccurred())
Expect(result.Stdout).To(Equal("stdout\n"))
Expect(result.Stderr).To(Equal("stderr\n"))
})
It("returns error and sets status to exit status of comamnd if it command exits with non-0 status", func() {
cmd := Command{Name: "bash", Args: []string{"-c", "exit 10"}}
process, err := runner.RunComplexCommandAsync(cmd)
Expect(err).ToNot(HaveOccurred())
//.........这里部分代码省略.........
开发者ID:keaty,项目名称:bosh-provisioner,代码行数:101,代码来源:exec_cmd_runner_test.go
示例10: init
//.........这里部分代码省略.........
osFs, _ := createOsFs()
file1, err := osFs.TempFile("fake-prefix")
Expect(err).ToNot(HaveOccurred())
assert.NotEmpty(GinkgoT(), file1)
defer os.Remove(file1.Name())
file2, err := osFs.TempFile("fake-prefix")
Expect(err).ToNot(HaveOccurred())
assert.NotEmpty(GinkgoT(), file2)
defer os.Remove(file2.Name())
assert.NotEqual(GinkgoT(), file1.Name(), file2.Name())
})
It("temp dir", func() {
osFs, _ := createOsFs()
path1, err := osFs.TempDir("fake-prefix")
Expect(err).ToNot(HaveOccurred())
assert.NotEmpty(GinkgoT(), path1)
defer os.Remove(path1)
path2, err := osFs.TempDir("fake-prefix")
Expect(err).ToNot(HaveOccurred())
assert.NotEmpty(GinkgoT(), path2)
defer os.Remove(path2)
assert.NotEqual(GinkgoT(), path1, path2)
})
Describe("CopyFile", func() {
It("copies file", func() {
osFs, _ := createOsFs()
srcPath := "../Fixtures/test_copy_dir_entries/foo.txt"
dstFile, err := osFs.TempFile("CopyFileTestFile")
Expect(err).ToNot(HaveOccurred())
defer os.Remove(dstFile.Name())
err = osFs.CopyFile(srcPath, dstFile.Name())
fooContent, err := osFs.ReadFileString(dstFile.Name())
Expect(err).ToNot(HaveOccurred())
Expect(fooContent).To(Equal("foo\n"))
})
It("does not leak file descriptors", func() {
osFs, _ := createOsFs()
srcFile, err := osFs.TempFile("srcPath")
Expect(err).ToNot(HaveOccurred())
err = srcFile.Close()
Expect(err).ToNot(HaveOccurred())
dstFile, err := osFs.TempFile("dstPath")
Expect(err).ToNot(HaveOccurred())
err = dstFile.Close()
Expect(err).ToNot(HaveOccurred())
err = osFs.CopyFile(srcFile.Name(), dstFile.Name())
Expect(err).ToNot(HaveOccurred())
runner := NewExecCmdRunner(boshlog.NewLogger(boshlog.LevelNone))
stdout, _, _, err := runner.RunCommand("lsof")
Expect(err).ToNot(HaveOccurred())
for _, line := range strings.Split(stdout, "\n") {
if strings.Contains(line, srcFile.Name()) {
Fail(fmt.Sprintf("CopyFile did not close: srcFile: %s", srcFile.Name()))
}
if strings.Contains(line, dstFile.Name()) {
Fail(fmt.Sprintf("CopyFile did not close: dstFile: %s", dstFile.Name()))
}
}
os.Remove(srcFile.Name())
os.Remove(dstFile.Name())
})
})
It("remove all", func() {
osFs, _ := createOsFs()
dstFile, err := osFs.TempFile("CopyFileTestFile")
Expect(err).ToNot(HaveOccurred())
defer os.Remove(dstFile.Name())
err = osFs.RemoveAll(dstFile.Name())
Expect(err).ToNot(HaveOccurred())
_, err = os.Stat(dstFile.Name())
Expect(os.IsNotExist(err)).To(BeTrue())
})
})
}
开发者ID:keaty,项目名称:bosh-provisioner,代码行数:101,代码来源:os_file_system_test.go
示例11: createOsFs
func createOsFs() (fs FileSystem, runner CmdRunner) {
logger := boshlog.NewLogger(boshlog.LevelNone)
fs = NewOsFileSystem(logger)
return
}
开发者ID:keaty,项目名称:bosh-provisioner,代码行数:5,代码来源:os_file_system_test.go
注:本文中的github.com/cloudfoundry/bosh-agent/logger.NewLogger函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论