本文整理汇总了Golang中github.com/cloudfoundry/bosh-utils/system/fakes.FakeFileSystem.RegisterReadFileError方法的典型用法代码示例。如果您正苦于以下问题:Golang FakeFileSystem.RegisterReadFileError方法的具体用法?Golang FakeFileSystem.RegisterReadFileError怎么用?Golang FakeFileSystem.RegisterReadFileError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cloudfoundry/bosh-utils/system/fakes.FakeFileSystem
的用法示例。
在下文中一共展示了FakeFileSystem.RegisterReadFileError方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1:
Expect(fakeBlobstore.GetError).ToNot(HaveOccurred())
Expect(fakeBlobstore.GetFileName).ToNot(Equal(""))
})
It("reads the DNS records from the blobstore file", func() {
response, err := syncDNS.Run("fake-blobstore-id", "fake-fingerprint")
Expect(err).ToNot(HaveOccurred())
Expect(response).To(Equal("synced"))
Expect(fakeBlobstore.GetError).ToNot(HaveOccurred())
Expect(fakeBlobstore.GetFileName).To(Equal("fake-blobstore-file-path"))
Expect(fakeFileSystem.ReadFileError).ToNot(HaveOccurred())
})
It("fails reading the DNS records from the blobstore file", func() {
fakeFileSystem.RegisterReadFileError("fake-blobstore-file-path", errors.New("fake-error"))
response, err := syncDNS.Run("fake-blobstore-id", "fake-fingerprint")
Expect(err).To(HaveOccurred())
Expect(response).To(Equal(""))
Expect(err.Error()).To(ContainSubstring("Reading fileName"))
})
It("deletes the file once read", func() {
_, err := syncDNS.Run("fake-blobstore-id", "fake-fingerprint")
Expect(err).ToNot(HaveOccurred())
Expect(fakeFileSystem.FileExists("fake-blobstore-file-path")).To(BeFalse())
})
It("logs when the dns blob file can't be deleted", func() {
示例2:
Context("When the path to the agent's state is ''", func() {
It("returns an error and a state object with false properties", func() {
s, err = platform.NewBootstrapState(fs, "")
Expect(s.Linux.HostsConfigured).To(BeFalse())
})
})
Context("When the agent cannot read the state file due to a failed disk", func() {
It("returns an error and a state object with false properties", func() {
fs.WriteFileString(path, `{
"hosts_configured": true,
"hostname_configured": true
}`)
fs.RegisterReadFileError(path, errors.New("ENXIO: disk failed"))
_, readerr := platform.NewBootstrapState(fs, path)
Expect(readerr.Error()).To(ContainSubstring("disk failed"))
})
})
Context("When the agent cannot parse the state file due to malformed JSON", func() {
It("returns an error and a state object with false properties", func() {
fs.WriteFileString(path, "malformed-JSON")
_, readerr := platform.NewBootstrapState(fs, path)
Expect(readerr).To(HaveOccurred())
})
示例3:
Expect(fakeBlobstore.GetError).ToNot(HaveOccurred())
Expect(fakeBlobstore.GetFileName).ToNot(Equal(""))
})
It("reads the DNS records from the blobstore file", func() {
response, err := action.Run("fake-blobstore-id", "fake-fingerprint", 2)
Expect(err).ToNot(HaveOccurred())
Expect(response).To(Equal("synced"))
Expect(fakeBlobstore.GetError).ToNot(HaveOccurred())
Expect(fakeBlobstore.GetFileName).To(Equal("fake-blobstore-file-path"))
Expect(fakeFileSystem.ReadFileError).ToNot(HaveOccurred())
})
It("fails reading the DNS records from the blobstore file", func() {
fakeFileSystem.RegisterReadFileError("fake-blobstore-file-path", errors.New("fake-error"))
response, err := action.Run("fake-blobstore-id", "fake-fingerprint", 2)
Expect(err).To(HaveOccurred())
Expect(response).To(Equal(""))
Expect(err.Error()).To(ContainSubstring("reading fake-blobstore-file-path from blobstore"))
Expect(fakeFileSystem.FileExists("fake-blobstore-file-path")).To(BeFalse())
})
It("deletes the file once read", func() {
_, err := action.Run("fake-blobstore-id", "fake-fingerprint", 2)
Expect(err).ToNot(HaveOccurred())
Expect(fakeFileSystem.FileExists("fake-blobstore-file-path")).To(BeFalse())
})