本文整理匯總了Golang中github.com/cloudfoundry/bosh-init/internal/github.com/cloudfoundry/bosh-utils/system/fakes.FakeFileSystem.ReadFileString方法的典型用法代碼示例。如果您正苦於以下問題:Golang FakeFileSystem.ReadFileString方法的具體用法?Golang FakeFileSystem.ReadFileString怎麽用?Golang FakeFileSystem.ReadFileString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cloudfoundry/bosh-init/internal/github.com/cloudfoundry/bosh-utils/system/fakes.FakeFileSystem
的用法示例。
在下文中一共展示了FakeFileSystem.ReadFileString方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1:
CurrentVMCID: "fake-vm-cid",
Disks: []DiskRecord{
{
CID: "fake-disk-cid",
Size: 1024,
CloudProperties: biproperty.Map{
"fake-disk-property-key": "fake-disk-property-value",
},
},
},
}
err := service.Save(config)
Expect(err).NotTo(HaveOccurred())
deploymentStateFileContents, err := fakeFs.ReadFileString(deploymentStatePath)
deploymentState := DeploymentState{
DirectorID: "deadbeef",
Stemcells: []StemcellRecord{
{
Name: "fake-stemcell-name",
Version: "fake-stemcell-version",
CID: "fake-stemcell-cid",
},
},
CurrentVMCID: "fake-vm-cid",
Disks: []DiskRecord{
{
CID: "fake-disk-cid",
Size: 1024,
CloudProperties: biproperty.Map{
示例2:
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())
示例3:
})
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{},
示例4:
})
It("deletes the legacy deployment state file", func() {
migrated, err := migrator.MigrateIfExists(legacyDeploymentStateFilePath)
Expect(migrated).To(BeTrue())
Expect(err).ToNot(HaveOccurred())
Expect(fakeFs.FileExists(legacyDeploymentStateFilePath)).To(BeFalse())
})
It("creates a new deployment state file without vm, disk, or stemcell", func() {
migrated, err := migrator.MigrateIfExists(legacyDeploymentStateFilePath)
Expect(migrated).To(BeTrue())
Expect(err).ToNot(HaveOccurred())
content, err := fakeFs.ReadFileString(modernDeploymentStateFilePath)
Expect(err).ToNot(HaveOccurred())
Expect(content).To(MatchRegexp(`{
"director_id": "fake-uuid-0",
"installation_id": "",
"current_vm_cid": "",
"current_stemcell_id": "",
"current_disk_id": "",
"current_release_ids": null,
"current_manifest_sha1": "",
"disks": \[\],
"stemcells": \[\],
"releases": \[\]
}`))
})
示例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:
Expect(fakeDavClient.GetPath).To(Equal("fake-blob-id"))
})
It("saves the blob to the destination path", func() {
fakeDavClient.GetContents = ioutil.NopCloser(strings.NewReader("fake-content"))
localBlob, err := blobstore.Get("fake-blob-id")
Expect(err).ToNot(HaveOccurred())
defer func() {
err := localBlob.Delete()
Expect(err).ToNot(HaveOccurred())
}()
Expect(localBlob.Path()).To(Equal("fake-destination-path"))
contents, err := fs.ReadFileString("fake-destination-path")
Expect(err).ToNot(HaveOccurred())
Expect(contents).To(Equal("fake-content"))
})
Context("when getting from blobstore fails", func() {
It("returns an error", func() {
fakeDavClient.GetErr = errors.New("fake-get-error")
_, err := blobstore.Get("fake-blob-id")
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-get-error"))
})
})
})