本文整理匯總了Golang中github.com/cloudfoundry/bosh-utils/system/fakes.FakeFileSystem.RenameError方法的典型用法代碼示例。如果您正苦於以下問題:Golang FakeFileSystem.RenameError方法的具體用法?Golang FakeFileSystem.RenameError怎麽用?Golang FakeFileSystem.RenameError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cloudfoundry/bosh-utils/system/fakes.FakeFileSystem
的用法示例。
在下文中一共展示了FakeFileSystem.RenameError方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1:
Expect(actualFs).To(Equal(fs))
Expect(path).To(Equal(installPath))
otherSourcePath := createSourcePath()
actualFs, path, err = fileBundle.Install(otherSourcePath)
Expect(err).NotTo(HaveOccurred())
Expect(actualFs).To(Equal(fs))
Expect(path).To(Equal(installPath))
Expect(fs.RenameOldPaths[0]).To(Equal(sourcePath))
Expect(fs.RenameNewPaths[0]).To(Equal(installPath))
})
It("returns error when moving source to install path fails", func() {
fs.RenameError = errors.New("fake-rename-error")
_, _, err := fileBundle.Install(sourcePath)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-rename-error"))
})
It("returns error when it fails to change permissions", func() {
fs.ChmodErr = errors.New("fake-chmod-error")
_, _, err := fileBundle.Install(sourcePath)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-chmod-error"))
})
It("does not install bundle if it fails to change permissions", func() {
示例2:
Expect(fs.FileExists(newLocation)).To(BeFalse())
err := mover.Move(oldLocation, newLocation)
Expect(err).ToNot(HaveOccurred())
Expect(fs.FileExists(oldLocation)).To(BeFalse())
contents, err := fs.ReadFileString(newLocation)
Expect(err).ToNot(HaveOccurred())
Expect(contents).To(Equal("some content"))
})
Context("when Rename fails due to EXDEV error", func() {
BeforeEach(func() {
fs.RenameError = &os.LinkError{
Err: syscall.Errno(0x12),
}
})
It("moves the file", func() {
Expect(fs.FileExists(oldLocation)).To(BeTrue())
Expect(fs.FileExists(newLocation)).To(BeFalse())
err := mover.Move(oldLocation, newLocation)
Expect(err).ToNot(HaveOccurred())
Expect(fs.FileExists(oldLocation)).To(BeFalse())
contents, err := fs.ReadFileString(newLocation)
Expect(err).ToNot(HaveOccurred())
Expect(contents).To(Equal("some content"))