本文整理匯總了Golang中github.com/cloudfoundry/bosh-init/internal/github.com/cloudfoundry/bosh-utils/system.FileSystem.WriteFileString方法的典型用法代碼示例。如果您正苦於以下問題:Golang FileSystem.WriteFileString方法的具體用法?Golang FileSystem.WriteFileString怎麽用?Golang FileSystem.WriteFileString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cloudfoundry/bosh-init/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:
BeforeEach(func() {
fs = boshsys.NewOsFileSystem(logger)
cmdRunner = boshsys.NewExecCmdRunner(logger)
compressor = boshcmd.NewTarballCompressor(cmdRunner, fs)
renderedJobListCompressor = NewRenderedJobListCompressor(fs, compressor, fakeSHA1Calculator, logger)
})
It("copies rendered jobs into a new temp dir, compresses the temp dir, and wraps it in a RenderedJobListArchive", func() {
// create rendered job with 2 rendered scripts
renderedJobDir0, err := fs.TempDir("RenderedJobListCompressorTest")
Expect(err).ToNot(HaveOccurred())
renderedJob0 := NewRenderedJob(bireljob.Job{Name: "fake-job-name-0"}, renderedJobDir0, fs, logger)
defer func() { err := renderedJob0.Delete(); Expect(err).ToNot(HaveOccurred()) }()
err = fs.WriteFileString(filepath.Join(renderedJobDir0, "script-0"), "fake-rendered-job-0-script-0-content")
Expect(err).ToNot(HaveOccurred())
err = fs.WriteFileString(filepath.Join(renderedJobDir0, "script-1"), "fake-rendered-job-0-script-1-content")
Expect(err).ToNot(HaveOccurred())
renderedJobList.Add(renderedJob0)
// create another rendered job with 1 rendered script
renderedJobDir1, err := fs.TempDir("RenderedJobListCompressorTest")
Expect(err).ToNot(HaveOccurred())
renderedJob1 := NewRenderedJob(bireljob.Job{Name: "fake-job-name-1"}, renderedJobDir1, fs, logger)
defer func() { err := renderedJob1.Delete(); Expect(err).ToNot(HaveOccurred()) }()
err = fs.WriteFileString(filepath.Join(renderedJobDir1, "script-0"), "fake-rendered-job-1-script-0-content")
Expect(err).ToNot(HaveOccurred())
renderedJobList.Add(renderedJob1)
// compress
示例4: GenerateDeploymentManifest
func GenerateDeploymentManifest(deploymentManifestFilePath string, fs boshsys.FileSystem, manifestContents string) error {
return fs.WriteFileString(deploymentManifestFilePath, manifestContents)
}