本文整理汇总了Golang中github.com/cloudfoundry/bosh-agent/system/fakes.NewFakeFileSystem函数的典型用法代码示例。如果您正苦于以下问题:Golang NewFakeFileSystem函数的具体用法?Golang NewFakeFileSystem怎么用?Golang NewFakeFileSystem使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewFakeFileSystem函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: createBlobManager
func createBlobManager() (blobManager BlobManager, fs *fakesys.FakeFileSystem) {
fs = fakesys.NewFakeFileSystem()
dirProvider := boshdir.NewDirectoriesProvider("/var/vcap")
blobManager = NewBlobManager(fs, dirProvider)
return
}
开发者ID:keaty,项目名称:bosh-provisioner,代码行数:7,代码来源:blob_manager_test.go
示例2: NewFakePlatform
func NewFakePlatform() (platform *FakePlatform) {
platform = new(FakePlatform)
platform.Fs = fakesys.NewFakeFileSystem()
platform.Runner = fakesys.NewFakeCmdRunner()
platform.FakeCompressor = fakecmd.NewFakeCompressor()
platform.FakeCopier = fakecmd.NewFakeCopier()
platform.FakeVitalsService = fakevitals.NewFakeService()
platform.DevicePathResolver = fakedpresolv.NewFakeDevicePathResolver()
platform.AddUserToGroupsGroups = make(map[string][]string)
platform.SetupSSHPublicKeys = make(map[string]string)
platform.UserPasswords = make(map[string]string)
platform.ScsiDiskMap = make(map[string]string)
return
}
开发者ID:keaty,项目名称:bosh-provisioner,代码行数:14,代码来源:fake_platform.go
示例3: init
func init() {
Describe("Testing with Ginkgo", func() {
It("new drain script", func() {
runner := fakesys.NewFakeCmdRunner()
fs := fakesys.NewFakeFileSystem()
dirProvider := boshdir.NewDirectoriesProvider("/var/vcap")
scriptProvider := NewConcreteDrainScriptProvider(runner, fs, dirProvider)
drainScript := scriptProvider.NewDrainScript("foo")
Expect(drainScript.Path()).To(Equal("/var/vcap/jobs/foo/bin/drain"))
})
})
}
开发者ID:keaty,项目名称:bosh-provisioner,代码行数:15,代码来源:concrete_drain_script_provider_test.go
示例4:
import (
fakesys "github.com/cloudfoundry/bosh-agent/system/fakes"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/sclevine/bosh-provisioner/main"
bpvm "github.com/sclevine/bosh-provisioner/vm"
)
var _ = Describe("NewConfigFromPath", func() {
var (
fs *fakesys.FakeFileSystem
)
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
})
It("defautls null values to agent provisioner config defaults", func() {
configJSON := `{
"manifest_path": "fake-manifest-path",
"assets_dir": "fake-assets-dir",
"repos_dir": "fake-repos-dir",
"blobstore": {
"provider": "local",
"options": {
"blobstore_path": "fake-blobstore-path"
}
},
"vm_provisioner": {
"agent_provisioner": {
开发者ID:keaty,项目名称:bosh-provisioner,代码行数:31,代码来源:config_test.go
示例5: init
func init() {
Describe("concreteV1Service", func() {
var (
fs *fakesys.FakeFileSystem
specPath = "/spec.json"
service V1Service
)
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
service = NewConcreteV1Service(fs, specPath)
})
Describe("Get", func() {
Context("when filesystem has a spec file", func() {
BeforeEach(func() {
fs.WriteFileString(specPath, `{"deployment":"fake-deployment-name"}`)
})
It("reads spec from filesystem", func() {
spec, err := service.Get()
Expect(err).ToNot(HaveOccurred())
Expect(spec).To(Equal(V1ApplySpec{Deployment: "fake-deployment-name"}))
})
It("returns error if reading spec from filesystem errs", func() {
fs.ReadFileError = errors.New("fake-read-error")
spec, err := service.Get()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-read-error"))
Expect(spec).To(Equal(V1ApplySpec{}))
})
})
Context("when filesystem does not have a spec file", func() {
It("reads spec from filesystem", func() {
spec, err := service.Get()
Expect(err).ToNot(HaveOccurred())
Expect(spec).To(Equal(V1ApplySpec{}))
})
})
})
Describe("Set", func() {
newSpec := V1ApplySpec{Deployment: "fake-deployment-name"}
It("writes spec to filesystem", func() {
err := service.Set(newSpec)
Expect(err).ToNot(HaveOccurred())
specPathStats := fs.GetFileTestStat(specPath)
Expect(specPathStats).ToNot(BeNil())
boshassert.MatchesJSONBytes(GinkgoT(), newSpec, specPathStats.Content)
})
It("returns error if writing spec to filesystem errs", func() {
fs.WriteToFileError = errors.New("fake-write-error")
err := service.Set(newSpec)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-write-error"))
})
})
Describe("PopulateDynamicNetworks", func() {
Context("when there are no dynamic networks", func() {
unresolvedSpec := V1ApplySpec{
Deployment: "fake-deployment",
NetworkSpecs: map[string]NetworkSpec{
"fake-net": NetworkSpec{
Fields: map[string]interface{}{"ip": "fake-net-ip"},
},
},
}
It("returns spec without modifying any networks", func() {
spec, err := service.PopulateDynamicNetworks(unresolvedSpec, boshsettings.Settings{})
Expect(err).ToNot(HaveOccurred())
Expect(spec).To(Equal(V1ApplySpec{
Deployment: "fake-deployment",
NetworkSpecs: map[string]NetworkSpec{
"fake-net": NetworkSpec{
Fields: map[string]interface{}{"ip": "fake-net-ip"},
},
},
}))
})
})
Context("when there are dynamic networks", func() {
unresolvedSpec := V1ApplySpec{
Deployment: "fake-deployment",
NetworkSpecs: map[string]NetworkSpec{
"fake-net1": NetworkSpec{
Fields: map[string]interface{}{
"ip": "fake-net1-ip",
"netmask": "fake-net1-netmask",
"gateway": "fake-net1-gateway",
},
//.........这里部分代码省略.........
开发者ID:keaty,项目名称:bosh-provisioner,代码行数:101,代码来源:concrete_v1_service_test.go
示例6: 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
示例7: 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
示例8: 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
示例9: init
func init() {
Describe("prepareNetworkChange", func() {
var (
action PrepareNetworkChangeAction
fs *fakesys.FakeFileSystem
settingsService *fakesettings.FakeSettingsService
)
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
settingsService = &fakesettings.FakeSettingsService{}
action = NewPrepareNetworkChange(fs, settingsService)
})
It("is synchronous", func() {
Expect(action.IsAsynchronous()).To(BeFalse())
})
It("is not persistent", func() {
Expect(action.IsPersistent()).To(BeFalse())
})
It("invalidates settings so that load settings cannot fall back on old settings", func() {
resp, err := action.Run()
Expect(err).NotTo(HaveOccurred())
Expect(resp).To(Equal("ok"))
Expect(settingsService.SettingsWereInvalidated).To(BeTrue())
})
Context("when settings invalidation succeeds", func() {
Context("when the network rules file can be removed", func() {
It("removes the network rules file", func() {
fs.WriteFile("/etc/udev/rules.d/70-persistent-net.rules", []byte{})
resp, err := action.Run()
Expect(err).NotTo(HaveOccurred())
Expect(resp).To(Equal("ok"))
Expect(fs.FileExists("/etc/udev/rules.d/70-persistent-net.rules")).To(BeFalse())
})
})
Context("when the network rules file cannot be removed", func() {
BeforeEach(func() {
fs.RemoveAllError = errors.New("fake-remove-all-error")
})
It("returns error from removing the network rules file", func() {
resp, err := action.Run()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-remove-all-error"))
Expect(resp).To(BeNil())
})
})
})
Context("when settings invalidation fails", func() {
BeforeEach(func() {
settingsService.InvalidateSettingsError = errors.New("fake-invalidate-error")
})
It("returns error early if settings err invalidating", func() {
resp, err := action.Run()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-invalidate-error"))
Expect(resp).To(BeNil())
})
It("does not remove the network rules file", func() {
fs.WriteFile("/etc/udev/rules.d/70-persistent-net.rules", []byte{})
action.Run()
Expect(fs.FileExists("/etc/udev/rules.d/70-persistent-net.rules")).To(BeTrue())
})
})
})
}
开发者ID:keaty,项目名称:bosh-provisioner,代码行数:80,代码来源:prepare_network_change_test.go
示例10: init
func init() {
Describe("Testing with Ginkgo", func() {
It("linux format when using swap fs", func() {
fakeRunner := fakesys.NewFakeCmdRunner()
fakeFs := fakesys.NewFakeFileSystem()
fakeRunner.AddCmdResult("blkid -p /dev/xvda1", fakesys.FakeCmdResult{Stdout: `xxxxx TYPE="ext4" yyyy zzzz`})
formatter := NewLinuxFormatter(fakeRunner, fakeFs)
formatter.Format("/dev/xvda1", FileSystemSwap)
Expect(2).To(Equal(len(fakeRunner.RunCommands)))
Expect(fakeRunner.RunCommands[1]).To(Equal([]string{"mkswap", "/dev/xvda1"}))
})
It("linux format when using swap fs and partition is swap", func() {
fakeRunner := fakesys.NewFakeCmdRunner()
fakeFs := fakesys.NewFakeFileSystem()
fakeRunner.AddCmdResult("blkid -p /dev/xvda1", fakesys.FakeCmdResult{Stdout: `xxxxx TYPE="swap" yyyy zzzz`})
formatter := NewLinuxFormatter(fakeRunner, fakeFs)
formatter.Format("/dev/xvda1", FileSystemSwap)
Expect(1).To(Equal(len(fakeRunner.RunCommands)))
Expect(fakeRunner.RunCommands[0]).To(Equal([]string{"blkid", "-p", "/dev/xvda1"}))
})
It("linux format when using ext4 fs with lazy itable support", func() {
fakeRunner := fakesys.NewFakeCmdRunner()
fakeFs := fakesys.NewFakeFileSystem()
fakeFs.WriteFile("/sys/fs/ext4/features/lazy_itable_init", []byte{})
fakeRunner.AddCmdResult("blkid -p /dev/xvda1", fakesys.FakeCmdResult{Stdout: `xxxxx TYPE="ext2" yyyy zzzz`})
formatter := NewLinuxFormatter(fakeRunner, fakeFs)
formatter.Format("/dev/xvda2", FileSystemExt4)
Expect(2).To(Equal(len(fakeRunner.RunCommands)))
Expect(fakeRunner.RunCommands[1]).To(Equal([]string{"mke2fs", "-t", "ext4", "-j", "-E", "lazy_itable_init=1", "/dev/xvda2"}))
})
It("linux format when using ext4 fs without lazy itable support", func() {
fakeRunner := fakesys.NewFakeCmdRunner()
fakeFs := fakesys.NewFakeFileSystem()
fakeRunner.AddCmdResult("blkid -p /dev/xvda1", fakesys.FakeCmdResult{Stdout: `xxxxx TYPE="ext2" yyyy zzzz`})
formatter := NewLinuxFormatter(fakeRunner, fakeFs)
formatter.Format("/dev/xvda2", FileSystemExt4)
Expect(2).To(Equal(len(fakeRunner.RunCommands)))
Expect(fakeRunner.RunCommands[1]).To(Equal([]string{"mke2fs", "-t", "ext4", "-j", "/dev/xvda2"}))
})
It("linux format when using ext4 fs and partition is ext4", func() {
fakeRunner := fakesys.NewFakeCmdRunner()
fakeFs := fakesys.NewFakeFileSystem()
fakeRunner.AddCmdResult("blkid -p /dev/xvda1", fakesys.FakeCmdResult{Stdout: `xxxxx TYPE="ext4" yyyy zzzz`})
formatter := NewLinuxFormatter(fakeRunner, fakeFs)
formatter.Format("/dev/xvda1", FileSystemExt4)
Expect(1).To(Equal(len(fakeRunner.RunCommands)))
Expect(fakeRunner.RunCommands[0]).To(Equal([]string{"blkid", "-p", "/dev/xvda1"}))
})
})
}
开发者ID:keaty,项目名称:bosh-provisioner,代码行数:65,代码来源:linux_formatter_test.go
示例11: 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
注:本文中的github.com/cloudfoundry/bosh-agent/system/fakes.NewFakeFileSystem函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论