本文整理汇总了Golang中github.com/cloudfoundry/bosh-agent/internal/github.com/cloudfoundry/bosh-utils/system.FileSystem.WriteFileString方法的典型用法代码示例。如果您正苦于以下问题:Golang FileSystem.WriteFileString方法的具体用法?Golang FileSystem.WriteFileString怎么用?Golang FileSystem.WriteFileString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cloudfoundry/bosh-agent/internal/github.com/cloudfoundry/bosh-utils/system.FileSystem
的用法示例。
在下文中一共展示了FileSystem.WriteFileString方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: describeDummyPlatform
func describeDummyPlatform() {
var (
platform Platform
collector boshstats.Collector
fs boshsys.FileSystem
cmdRunner boshsys.CmdRunner
dirProvider boshdirs.Provider
devicePathResolver boshdpresolv.DevicePathResolver
logger boshlog.Logger
)
BeforeEach(func() {
collector = &fakestats.FakeCollector{}
fs = fakesys.NewFakeFileSystem()
cmdRunner = fakesys.NewFakeCmdRunner()
dirProvider = boshdirs.NewProvider("/fake-dir")
devicePathResolver = fakedpresolv.NewFakeDevicePathResolver()
logger = boshlog.NewLogger(boshlog.LevelNone)
})
JustBeforeEach(func() {
platform = NewDummyPlatform(
collector,
fs,
cmdRunner,
dirProvider,
devicePathResolver,
logger,
)
})
Describe("GetDefaultNetwork", func() {
It("returns the contents of dummy-defaults-network-settings.json since that's what the dummy cpi writes", func() {
settingsFilePath := "/fake-dir/bosh/dummy-default-network-settings.json"
fs.WriteFileString(settingsFilePath, `{"IP": "1.2.3.4"}`)
network, err := platform.GetDefaultNetwork()
Expect(err).NotTo(HaveOccurred())
Expect(network.IP).To(Equal("1.2.3.4"))
})
})
Describe("GetCertManager", func() {
It("returs a dummy cert manager", func() {
certManager := platform.GetCertManager()
Expect(certManager.UpdateCertificates("")).Should(BeNil())
})
})
}
示例2:
Expect(cmdRunner.RunCommands[0]).To(Equal(
[]string{
"tar", "--same-owner",
"-xzvf", tarballPath,
"-C", dstDir,
},
))
})
})
Describe("CleanUp", func() {
It("removes tarball path", func() {
fs := fakesys.NewFakeFileSystem()
compressor := NewTarballCompressor(cmdRunner, fs)
err := fs.WriteFileString("/fake-tarball.tar", "")
Expect(err).ToNot(HaveOccurred())
err = compressor.CleanUp("/fake-tarball.tar")
Expect(err).ToNot(HaveOccurred())
Expect(fs.FileExists("/fake-tarball.tar")).To(BeFalse())
})
It("returns error if removing tarball path fails", func() {
fs := fakesys.NewFakeFileSystem()
compressor := NewTarballCompressor(cmdRunner, fs)
fs.RemoveAllError = errors.New("fake-remove-all-err")
err := compressor.CleanUp("/fake-tarball.tar")
示例3:
blobId = "105d33ae-655c-493d-bf9f-1df5cf3ca847"
basePath = "/tmp"
blobPath = filepath.Join(basePath, blobId)
toWrite = bytes.NewReader([]byte("new data"))
})
readFile := func(fileIO boshsys.File) []byte {
fileStat, _ := fileIO.Stat()
fileBytes := make([]byte, fileStat.Size())
fileIO.Read(fileBytes)
return fileBytes
}
It("fetches", func() {
blobManager := NewBlobManager(fs, basePath)
fs.WriteFileString(blobPath, "some data")
readOnlyFile, err, _ := blobManager.Fetch(blobId)
defer fs.RemoveAll(readOnlyFile.Name())
Expect(err).ToNot(HaveOccurred())
fileBytes := readFile(readOnlyFile)
Expect(string(fileBytes)).To(Equal("some data"))
})
It("writes", func() {
blobManager := NewBlobManager(fs, basePath)
fs.WriteFileString(blobPath, "some data")
defer fs.RemoveAll(blobPath)
示例4: init
//.........这里部分代码省略.........
It("uses a VirtioDevicePathResolver", func() {
err := app.Setup([]string{"bosh-agent", "-P", "dummy", "-C", agentConfPath, "-b", baseDir})
Expect(err).ToNot(HaveOccurred())
logLevel, err := boshlog.Levelify("DEBUG")
Expect(err).NotTo(HaveOccurred())
Expect(app.GetPlatform().GetDevicePathResolver()).To(
BeAssignableToTypeOf(devicepathresolver.NewVirtioDevicePathResolver(nil, nil, boshlog.NewLogger(logLevel))))
})
})
Context("when DevicePathResolutionType is 'scsi'", func() {
BeforeEach(func() {
agentConfJSON = `{
"Platform": { "Linux": { "DevicePathResolutionType": "scsi" } },
"Infrastructure": { "Settings": { "Sources": [{ "Type": "CDROM", "FileName": "/fake-file-name" }] } }
}`
})
It("uses a VirtioDevicePathResolver", func() {
err := app.Setup([]string{"bosh-agent", "-P", "dummy", "-C", agentConfPath, "-b", baseDir})
Expect(err).ToNot(HaveOccurred())
Expect(app.GetPlatform().GetDevicePathResolver()).To(
BeAssignableToTypeOf(devicepathresolver.NewScsiDevicePathResolver(0, nil)))
})
})
Context("logging stemcell version and git sha", func() {
var (
logger boshlog.Logger
outBuf *bytes.Buffer
fakeFs boshsys.FileSystem
stemcellVersionFilePath string
stemcellSha1FilePath string
)
JustBeforeEach(func() {
outBuf = bytes.NewBufferString("")
errBuf := bytes.NewBufferString("")
logger = boshlog.NewWriterLogger(boshlog.LevelDebug, outBuf, errBuf)
fakeFs = fakesys.NewFakeFileSystem()
dirProvider := boshdirs.NewProvider(baseDir)
stemcellVersionFilePath = filepath.Join(dirProvider.EtcDir(), "stemcell_version")
stemcellSha1FilePath = filepath.Join(dirProvider.EtcDir(), "stemcell_git_sha1")
app = New(logger, fakeFs)
})
Context("when stemcell version and sha files are present", func() {
It("should print out the stemcell version and sha in the logs", func() {
fakeFs.WriteFileString(stemcellVersionFilePath, "version-blah")
fakeFs.WriteFileString(stemcellSha1FilePath, "sha1-blah")
app.Setup([]string{"bosh-agent", "-P", "dummy", "-C", agentConfPath, "-b", baseDir})
Expect(string(outBuf.Bytes())).To(ContainSubstring("Running on stemcell version 'version-blah' (git: sha1-blah)"))
})
})
Context("when stemcell version file is NOT present", func() {
It("should print out the sha in the logs", func() {
fakeFs.WriteFileString(stemcellSha1FilePath, "sha1-blah")
app.Setup([]string{"bosh-agent", "-P", "dummy", "-C", agentConfPath, "-b", baseDir})
Expect(string(outBuf.Bytes())).To(ContainSubstring("Running on stemcell version '?' (git: sha1-blah)"))
})
})
Context("when sha version file is NOT present", func() {
It("should print out the stemcell version in the logs", func() {
fakeFs.WriteFileString(stemcellVersionFilePath, "version-blah")
app.Setup([]string{"bosh-agent", "-P", "dummy", "-C", agentConfPath, "-b", baseDir})
Expect(string(outBuf.Bytes())).To(ContainSubstring("Running on stemcell version 'version-blah' (git: ?)"))
})
})
Context("when stemcell version file is empty", func() {
It("should print out the sha in the logs", func() {
fakeFs.WriteFileString(stemcellVersionFilePath, "")
fakeFs.WriteFileString(stemcellSha1FilePath, "sha1-blah")
app.Setup([]string{"bosh-agent", "-P", "dummy", "-C", agentConfPath, "-b", baseDir})
Expect(string(outBuf.Bytes())).To(ContainSubstring("Running on stemcell version '?' (git: sha1-blah)"))
})
})
Context("when sha version file is empty", func() {
It("should print out the stemcell version in the logs", func() {
fakeFs.WriteFileString(stemcellVersionFilePath, "version-blah")
fakeFs.WriteFileString(stemcellSha1FilePath, "")
app.Setup([]string{"bosh-agent", "-P", "dummy", "-C", agentConfPath, "-b", baseDir})
Expect(string(outBuf.Bytes())).To(ContainSubstring("Running on stemcell version 'version-blah' (git: ?)"))
})
})
Context("when stemcell version and sha files are NOT present", func() {
It("should print unknown version and sha in the logs", func() {
app.Setup([]string{"bosh-agent", "-P", "dummy", "-C", agentConfPath, "-b", baseDir})
Expect(string(outBuf.Bytes())).To(ContainSubstring("Running on stemcell version '?' (git: ?)"))
})
})
})
})
}