本文整理匯總了Golang中github.com/cloudfoundry/bosh-agent/system/fakes.FakeFileSystem.WriteFileString方法的典型用法代碼示例。如果您正苦於以下問題:Golang FakeFileSystem.WriteFileString方法的具體用法?Golang FakeFileSystem.WriteFileString怎麽用?Golang FakeFileSystem.WriteFileString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cloudfoundry/bosh-agent/system/fakes.FakeFileSystem
的用法示例。
在下文中一共展示了FakeFileSystem.WriteFileString方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1:
"provider": "local",
"options": {
"blobstore_path": "fake-blobstore-path"
}
},
"vm_provisioner": {
"agent_provisioner": {
"infrastructure": null,
"platform": null,
"configuration": null,
"mbus": null
}
}
}`
err := fs.WriteFileString("/tmp/config", configJSON)
Expect(err).ToNot(HaveOccurred())
config, err := NewConfigFromPath("/tmp/config", fs)
Expect(err).ToNot(HaveOccurred())
Expect(config.VMProvisioner.AgentProvisioner).To(Equal(
bpvm.AgentProvisionerConfig{
Infrastructure: "warden",
Platform: "ubuntu",
Configuration: map[string]interface{}{
"Platform": map[string]interface{}{
"Linux": map[string]interface{}{
"UseDefaultTmpDir": true,
},
示例2: init
//.........這裏部分代碼省略.........
})
Context("when job is not installed", func() {
BeforeEach(func() {
bundle.Installed = false
})
It("installs and enables job", func() {
err := act()
Expect(err).ToNot(HaveOccurred())
Expect(bundle.ActionsCalled).To(Equal([]string{"Install", "Enable"}))
})
It("returns error when job enable fails", func() {
bundle.EnableError = errors.New("fake-enable-error")
err := act()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-enable-error"))
})
ItInstallsJob(act)
ItUpdatesPackages(act)
})
})
})
Describe("Configure", func() {
It("adds job to the job supervisor", func() {
job, bundle := buildJob(jobsBc)
fs := fakesys.NewFakeFileSystem()
fs.WriteFileString("/path/to/job/monit", "some conf")
fs.SetGlob("/path/to/job/*.monit", []string{"/path/to/job/subjob.monit"})
bundle.GetDirPath = "/path/to/job"
bundle.GetDirFs = fs
err := applier.Configure(job, 0)
Expect(err).ToNot(HaveOccurred())
Expect(len(jobSupervisor.AddJobArgs)).To(Equal(2))
Expect(jobSupervisor.AddJobArgs[0]).To(Equal(fakejobsuper.AddJobArgs{
Name: job.Name,
Index: 0,
ConfigPath: "/path/to/job/monit",
}))
Expect(jobSupervisor.AddJobArgs[1]).To(Equal(fakejobsuper.AddJobArgs{
Name: job.Name + "_subjob",
Index: 0,
ConfigPath: "/path/to/job/subjob.monit",
}))
})
It("does not require monit script", func() {
job, bundle := buildJob(jobsBc)
fs := fakesys.NewFakeFileSystem()
bundle.GetDirFs = fs
err := applier.Configure(job, 0)
Expect(err).ToNot(HaveOccurred())
Expect(len(jobSupervisor.AddJobArgs)).To(Equal(0))
示例3: 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",
},
//.........這裏部分代碼省略.........
示例4:
}))
})
}
Context("when dhclient3 is installed on the system", func() {
BeforeEach(func() { cmdRunner.CommandExistsValue = true })
Context("when dhcp was not previously configured", func() {
ItUpdatesDhcpConfig(dhcp3ConfPath)
ItRestartsDhcp()
ItBroadcastsMACAddresses()
})
Context("when dhcp was previously configured with different configuration", func() {
BeforeEach(func() {
fs.WriteFileString(dhcp3ConfPath, "fake-other-configuration")
})
ItUpdatesDhcpConfig(dhcp3ConfPath)
ItRestartsDhcp()
ItBroadcastsMACAddresses()
})
Context("when dhcp was previously configured with the same configuration", func() {
BeforeEach(func() {
fs.WriteFileString(dhcp3ConfPath, expectedDHCPConfig)
})
ItUpdatesDhcpConfig(dhcp3ConfPath)
ItDoesNotRestartDhcp()
ItBroadcastsMACAddresses()
示例5:
failureHandler := func(alert boshalert.MonitAlert) (err error) {
didHandleAlert = true
return
}
go monit.MonitorJobFailures(failureHandler)
err := doJobFailureEmail(`fake-other-email`, jobFailuresServerPort)
Expect(err).ToNot(HaveOccurred())
Expect(didHandleAlert).To(BeFalse())
})
})
Describe("AddJob", func() {
BeforeEach(func() {
fs.WriteFileString("/some/config/path", "fake-config")
})
Context("when reading configuration from config path succeeds", func() {
Context("when writing job configuration succeeds", func() {
It("returns no error because monit can track added job in jobs directory", func() {
err := monit.AddJob("router", 0, "/some/config/path")
Expect(err).ToNot(HaveOccurred())
writtenConfig, err := fs.ReadFileString(
dirProvider.MonitJobsDir() + "/0000_router.monitrc")
Expect(err).ToNot(HaveOccurred())
Expect(writtenConfig).To(Equal("fake-config"))
})
})
示例6:
Expect(err).ToNot(HaveOccurred())
Expect(len(cmdRunner.RunCommands)).To(Equal(1))
Expect(cmdRunner.RunCommands[0]).To(Equal([]string{"service", "network", "restart"}))
})
}
Context("when dhcp was not previously configured", func() {
ItUpdatesDhcpConfig()
ItRestartsDhcp()
ItBroadcastsMACAddresses()
})
Context("when dhcp was previously configured with different configuration", func() {
BeforeEach(func() {
fs.WriteFileString(dhcpConfPath, "fake-other-configuration")
})
ItUpdatesDhcpConfig()
ItRestartsDhcp()
ItBroadcastsMACAddresses()
})
Context("when dhcp was previously configured with same configuration", func() {
BeforeEach(func() {
fs.WriteFileString(dhcpConfPath, expectedDHCPConfig)
})
It("keeps dhcp configuration", func() {
err := netManager.SetupDhcp(networks, nil)
Expect(err).ToNot(HaveOccurred())
示例7:
Expect(err.Error()).To(ContainSubstring("missing blobstore_path"))
})
It("returns error when blobstore path is not a string", func() {
options := map[string]interface{}{"blobstore_path": 443}
blobstore = NewLocalBlobstore(fs, uuidGen, options)
err := blobstore.Validate()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("blobstore_path must be a string"))
})
})
Describe("Get", func() {
It("local get", func() {
fs.WriteFileString(fakeBlobstorePath+"/fake-blob-id", "fake contents")
tempFile, err := fs.TempFile("bosh-blobstore-local-TestLocalGet")
Expect(err).ToNot(HaveOccurred())
fs.ReturnTempFile = tempFile
defer fs.RemoveAll(tempFile.Name())
_, err = blobstore.Get("fake-blob-id", "")
Expect(err).ToNot(HaveOccurred())
fileStats := fs.GetFileTestStat(tempFile.Name())
Expect(fileStats).ToNot(BeNil())
Expect("fake contents").To(Equal(fileStats.StringContents()))
})
示例8:
fs *fakesys.FakeFileSystem
searcher MountsSearcher
)
BeforeEach(func() {
fs = fakesys.NewFakeFileSystem()
searcher = NewProcMountsSearcher(fs)
})
Describe("SearchMounts", func() {
Context("when reading /proc/mounts succeeds", func() {
It("returns parsed mount information", func() {
fs.WriteFileString(
"/proc/mounts",
`none /run/lock tmpfs rw,nosuid,nodev,noexec,relatime,size=5120k 0 0
none /run/shm tmpfs rw,nosuid,nodev,relatime 0 0
/dev/sda1 /boot ext2 rw,relatime,errors=continue 0 0
none /tmp/warden/cgroup tmpfs rw,relatime 0 0`,
)
mounts, err := searcher.SearchMounts()
Expect(err).ToNot(HaveOccurred())
Expect(mounts).To(Equal([]Mount{
Mount{PartitionPath: "none", MountPoint: "/run/lock"},
Mount{PartitionPath: "none", MountPoint: "/run/shm"},
Mount{PartitionPath: "/dev/sda1", MountPoint: "/boot"},
Mount{PartitionPath: "none", MountPoint: "/tmp/warden/cgroup"},
}))
})
It("ignores empty lines", func() {