本文整理匯總了Golang中github.com/cloudfoundry/bosh-agent/internal/github.com/cloudfoundry/bosh-utils/system/fakes.FakeFileSystem.ReadFileString方法的典型用法代碼示例。如果您正苦於以下問題:Golang FakeFileSystem.ReadFileString方法的具體用法?Golang FakeFileSystem.ReadFileString怎麽用?Golang FakeFileSystem.ReadFileString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cloudfoundry/bosh-agent/internal/github.com/cloudfoundry/bosh-utils/system/fakes.FakeFileSystem
的用法示例。
在下文中一共展示了FakeFileSystem.ReadFileString方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1:
It("updates the blob on the file system", func() {
fs.WriteFileString("/var/vcap/micro_bosh/data/cache/123-456-789", "Some data")
putBody := `Updated data`
putPayload := strings.NewReader(putBody)
request, err := http.NewRequest("PUT", serverURL+"/blobs/a5/123-456-789", putPayload)
Expect(err).ToNot(HaveOccurred())
httpResponse, err := httpClient.Do(request)
Expect(err).ToNot(HaveOccurred())
defer httpResponse.Body.Close()
Expect(httpResponse.StatusCode).To(Equal(201))
contents, err := fs.ReadFileString("/var/vcap/micro_bosh/data/cache/123-456-789")
Expect(err).ToNot(HaveOccurred())
Expect(contents).To(Equal("Updated data"))
})
Context("when manager errors", func() {
It("returns a 500 because of openfile error", func() {
fs.OpenFileErr = errors.New("oops")
putBody := `Updated data`
putPayload := strings.NewReader(putBody)
request, err := http.NewRequest("PUT", serverURL+"/blobs/a5/123-456-789", putPayload)
Expect(err).ToNot(HaveOccurred())
httpResponse, err := httpClient.Do(request)
示例2:
Stderr: "fake-stderr",
ExitStatus: 0,
Error: nil,
})
})
It("saves stdout/stderr to log file", func() {
runScriptResult := genericScript.Run()
Expect(runScriptResult.Tag).To(Equal("my-tag"))
Expect(runScriptResult.Error).To(BeNil())
Expect(fs.FileExists(stdoutLogPath)).To(BeTrue())
Expect(fs.FileExists(stderrLogPath)).To(BeTrue())
stdout, err := fs.ReadFileString(stdoutLogPath)
Expect(err).ToNot(HaveOccurred())
Expect(stdout).To(Equal("fake-stdout"))
stderr, err := fs.ReadFileString(stderrLogPath)
Expect(err).ToNot(HaveOccurred())
Expect(stderr).To(Equal("fake-stderr"))
})
})
Context("when command fails", func() {
BeforeEach(func() {
cmdRunner.AddCmdResult("/path-to-script", fakesys.FakeCmdResult{
Stdout: "fake-stdout",
Stderr: "fake-stderr",
示例3: describeLinuxPlatform
//.........這裏部分代碼省略.........
Expect(authKeysStat).NotTo(BeNil())
Expect(fakesys.FakeFileTypeFile).To(Equal(authKeysStat.FileType))
Expect(os.FileMode(0600)).To(Equal(authKeysStat.FileMode))
Expect("vcap").To(Equal(authKeysStat.Username))
Expect("some public key").To(Equal(authKeysStat.StringContents()))
})
})
Describe("SetUserPassword", func() {
It("set user password", func() {
platform.SetUserPassword("my-user", "my-encrypted-password")
Expect(len(cmdRunner.RunCommands)).To(Equal(1))
Expect(cmdRunner.RunCommands[0]).To(Equal([]string{"usermod", "-p", "my-encrypted-password", "my-user"}))
})
})
Describe("SetupHostname", func() {
const expectedEtcHosts = `127.0.0.1 localhost foobar.local
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback foobar.local
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
`
It("sets up hostname", func() {
platform.SetupHostname("foobar.local")
Expect(len(cmdRunner.RunCommands)).To(Equal(1))
Expect(cmdRunner.RunCommands[0]).To(Equal([]string{"hostname", "foobar.local"}))
hostnameFileContent, err := fs.ReadFileString("/etc/hostname")
Expect(err).NotTo(HaveOccurred())
Expect(hostnameFileContent).To(Equal("foobar.local"))
hostsFileContent, err := fs.ReadFileString("/etc/hosts")
Expect(err).NotTo(HaveOccurred())
Expect(hostsFileContent).To(Equal(expectedEtcHosts))
})
})
Describe("SetupLogrotate", func() {
const expectedEtcLogrotate = `# Generated by bosh-agent
fake-base-path/data/sys/log/*.log fake-base-path/data/sys/log/*/*.log fake-base-path/data/sys/log/*/*/*.log {
missingok
rotate 7
compress
delaycompress
copytruncate
size=fake-size
}
`
It("sets up logrotate", func() {
platform.SetupLogrotate("fake-group-name", "fake-base-path", "fake-size")
logrotateFileContent, err := fs.ReadFileString("/etc/logrotate.d/fake-group-name")
Expect(err).NotTo(HaveOccurred())
Expect(logrotateFileContent).To(Equal(expectedEtcLogrotate))
})
})
示例4:
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.WriteFileError = 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"))
})
})
})
示例5:
configPath = filepath.Join("/etc/", "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"))
})
示例6:
})
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",
})
diskSettings = boshsettings.DiskSettings{
VolumeID: "fake-disk-id",
}
})
Describe("GetRealDevicePath", func() {
It("rescans the devices attached to the root disks scsi controller", func() {
resolver.GetRealDevicePath(diskSettings)
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, timedOut, err := resolver.GetRealDevicePath(diskSettings)
Expect(err).NotTo(HaveOccurred())
Expect(timedOut).To(BeFalse())
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{},
示例7:
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"))
})
})
示例8:
err = logFile.Close()
Expect(err).ToNot(HaveOccurred())
})
AfterEach(func() {
logFile.Close()
fs.RemoveAll(logFile.Name())
})
It("logs the formatted DEBUG message to the file", func() {
logger, logFile, err := New(boshlog.LevelDebug, logFile.Name(), DefaultLogFileMode, fs)
Expect(err).ToNot(HaveOccurred())
logger.Debug("TAG", "some %s info to log", "awesome")
contents, err := fs.ReadFileString(logFile.Name())
Expect(err).ToNot(HaveOccurred())
expectedContent := expectedLogFormat("TAG", "DEBUG - some awesome info to log")
Expect(contents).To(MatchRegexp(expectedContent))
})
It("logs the formatted INFO message to the file", func() {
logger, logFile, err := New(boshlog.LevelDebug, logFile.Name(), DefaultLogFileMode, fs)
Expect(err).ToNot(HaveOccurred())
logger.Info("TAG", "some %s info to log", "awesome")
contents, err := fs.ReadFileString(logFile.Name())
Expect(err).ToNot(HaveOccurred())