本文整理匯總了Golang中github.com/cloudfoundry/bosh-agent/system/fakes.FakeFileSystem.ReadFileString方法的典型用法代碼示例。如果您正苦於以下問題:Golang FakeFileSystem.ReadFileString方法的具體用法?Golang FakeFileSystem.ReadFileString怎麽用?Golang FakeFileSystem.ReadFileString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cloudfoundry/bosh-agent/system/fakes.FakeFileSystem
的用法示例。
在下文中一共展示了FakeFileSystem.ReadFileString方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1:
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"))
})
})
Context("when writing job configuration fails", func() {
It("returns error", func() {
fs.WriteToFileError = errors.New("fake-write-error")
err := monit.AddJob("router", 0, "/some/config/path")
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-write-error"))
})
})
})
示例2:
Stderr: []byte("fake-stderr"),
ExitStatus: 0,
}
result, err := runner.RunCommand("fake-log-dir-name", "fake-log-file-name", cmd)
Expect(err).ToNot(HaveOccurred())
Expect(result).To(Equal(expectedResult))
})
It("saves stdout to log file", func() {
_, err := runner.RunCommand("fake-log-dir-name", "fake-log-file-name", cmd)
Expect(err).ToNot(HaveOccurred())
Expect(fs.FileExists("/fake-base-dir/fake-log-dir-name/fake-log-file-name.stdout.log")).To(BeTrue())
stdout, err := fs.ReadFileString("/fake-base-dir/fake-log-dir-name/fake-log-file-name.stdout.log")
Expect(err).ToNot(HaveOccurred())
Expect(stdout).To(Equal("fake-stdout"))
})
It("saves stderr to log file", func() {
_, err := runner.RunCommand("fake-log-dir-name", "fake-log-file-name", cmd)
Expect(err).ToNot(HaveOccurred())
Expect(fs.FileExists("/fake-base-dir/fake-log-dir-name/fake-log-file-name.stderr.log")).To(BeTrue())
stdout, err := fs.ReadFileString("/fake-base-dir/fake-log-dir-name/fake-log-file-name.stderr.log")
Expect(err).ToNot(HaveOccurred())
Expect(stdout).To(Equal("fake-stderr"))
})
})
示例3:
fs.SetGlob("/sys/bus/scsi/devices/*:0:0:0/block/*", []string{
"/sys/bus/scsi/devices/0:0:0:0/block/sr0",
"/sys/bus/scsi/devices/6:0:0:0/block/sdd",
"/sys/bus/scsi/devices/fake-host-id:0:0:0/block/sda",
})
fs.SetGlob("/sys/bus/scsi/devices/fake-host-id:0:fake-disk-id:0/block/*", []string{
"/sys/bus/scsi/devices/fake-host-id:0:fake-disk-id:0/block/sdf",
})
})
Describe("GetRealDevicePath", func() {
It("rescans the devices attached to the root disks scsi controller", func() {
resolver.GetRealDevicePath("fake-disk-id")
scanContents, err := fs.ReadFileString("/sys/class/scsi_host/hostfake-host-id/scan")
Expect(err).NotTo(HaveOccurred())
Expect(scanContents).To(Equal("- - -"))
})
It("detects device", func() {
devicePath, err := resolver.GetRealDevicePath("fake-disk-id")
Expect(err).NotTo(HaveOccurred())
Expect(devicePath).To(Equal("/dev/sdf"))
})
Context("when device does not immediately appear", func() {
It("retries detection of device", func() {
fs.SetGlob("/sys/bus/scsi/devices/fake-host-id:0:fake-disk-id:0/block/*",
[]string{},
[]string{},
示例4:
configPath = filepath.Join(dirProvider.EtcDir(), "blobstore-fake-provider.json")
blobstore = NewExternalBlobstore("fake-provider", map[string]interface{}{}, fs, runner, uuidGen, configPath)
})
Describe("Validate", func() {
It("external validate writes config file", func() {
options := map[string]interface{}{"fake-key": "fake-value"}
blobstore := NewExternalBlobstore("fake-provider", options, fs, runner, uuidGen, configPath)
runner.CommandExistsValue = true
err := blobstore.Validate()
Expect(err).ToNot(HaveOccurred())
s3CliConfig, err := fs.ReadFileString(configPath)
Expect(err).ToNot(HaveOccurred())
expectedJSON := map[string]string{"fake-key": "fake-value"}
boshassert.MatchesJSONString(GinkgoT(), expectedJSON, s3CliConfig)
})
It("external validate errors when command not in path", func() {
options := map[string]interface{}{}
blobstore := NewExternalBlobstore("fake-provider", options, fs, runner, uuidGen, configPath)
err := blobstore.Validate()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("not found in PATH"))
})