本文整理匯總了Golang中bosh/system/fakes.FakeFileSystem.RemoveAll方法的典型用法代碼示例。如果您正苦於以下問題:Golang FakeFileSystem.RemoveAll方法的具體用法?Golang FakeFileSystem.RemoveAll怎麽用?Golang FakeFileSystem.RemoveAll使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類bosh/system/fakes.FakeFileSystem
的用法示例。
在下文中一共展示了FakeFileSystem.RemoveAll方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1:
err := blobstore.Validate()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("blobstore_path must be a string"))
})
})
Describe("Get", func() {
It("local get", func() {
fs.WriteFileString(fakeBlobstorePath+"/fake-blob-id", "fake contents")
tempFile, err := fs.TempFile("bosh-blobstore-local-TestLocalGet")
Expect(err).ToNot(HaveOccurred())
fs.ReturnTempFile = tempFile
defer fs.RemoveAll(tempFile.Name())
_, err = blobstore.Get("fake-blob-id", "")
Expect(err).ToNot(HaveOccurred())
fileStats := fs.GetFileTestStat(tempFile.Name())
Expect(fileStats).ToNot(BeNil())
Expect("fake contents").To(Equal(fileStats.StringContents()))
})
It("local get errs when temp file create errs", func() {
fs.TempFileError = errors.New("fake-error")
fileName, err := blobstore.Get("fake-blob-id", "")
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-error"))
示例2:
contents, err := platform.GetFileContentsFromCDROM(filename)
Expect(err).NotTo(HaveOccurred())
Expect(cdutil.GetFileContentsFilename).To(Equal(filename))
Expect(contents).To(Equal(cdutil.GetFileContentsContents))
})
})
Describe("NormalizeDiskPath", func() {
It("normalize disk path", func() {
fs.WriteFile("/dev/xvda", []byte{})
path, found := platform.NormalizeDiskPath("/dev/sda")
Expect("/dev/xvda").To(Equal(path))
Expect(found).To(BeTrue())
fs.RemoveAll("/dev/xvda")
fs.WriteFile("/dev/vda", []byte{})
path, found = platform.NormalizeDiskPath("/dev/sda")
Expect("/dev/vda").To(Equal(path))
Expect(found).To(BeTrue())
fs.RemoveAll("/dev/vda")
fs.WriteFile("/dev/sda", []byte{})
path, found = platform.NormalizeDiskPath("/dev/sda")
Expect("/dev/sda").To(Equal(path))
Expect(found).To(BeTrue())
})
It("get real device path with multiple possible devices", func() {
示例3: init
//.........這裏部分代碼省略.........
fakeMounter := diskManager.FakeMounter
fakeMounter.UnmountDidUnmount = false
fs.WriteToFile("/dev/vdx", "")
didUnmount, err := platform.UnmountPersistentDisk("/dev/sdx")
assert.NoError(GinkgoT(), err)
assert.Equal(GinkgoT(), didUnmount, false)
assert.Equal(GinkgoT(), "/dev/vdx1", fakeMounter.UnmountPartitionPath)
})
})
Context("when already mounted", func() {
It("unmounts persistent disk", func() {
fakeMounter := diskManager.FakeMounter
fakeMounter.UnmountDidUnmount = true
fs.WriteToFile("/dev/vdx", "")
didUnmount, err := platform.UnmountPersistentDisk("/dev/sdx")
assert.NoError(GinkgoT(), err)
assert.Equal(GinkgoT(), didUnmount, true)
assert.Equal(GinkgoT(), "/dev/vdx1", fakeMounter.UnmountPartitionPath)
})
})
It("ubuntu normalize disk path", func() {
fs.WriteToFile("/dev/xvda", "")
path, found := platform.NormalizeDiskPath("/dev/sda")
assert.Equal(GinkgoT(), path, "/dev/xvda")
assert.True(GinkgoT(), found)
fs.RemoveAll("/dev/xvda")
fs.WriteToFile("/dev/vda", "")
path, found = platform.NormalizeDiskPath("/dev/sda")
assert.Equal(GinkgoT(), path, "/dev/vda")
assert.True(GinkgoT(), found)
fs.RemoveAll("/dev/vda")
fs.WriteToFile("/dev/sda", "")
path, found = platform.NormalizeDiskPath("/dev/sda")
assert.Equal(GinkgoT(), path, "/dev/sda")
assert.True(GinkgoT(), found)
})
Describe("GetFileContentsFromCDROM", func() {
It("delegates to cdutil", func() {
cdutil.GetFileContentsContents = []byte("fake-contents")
filename := "fake-env"
contents, err := platform.GetFileContentsFromCDROM(filename)
Expect(err).NotTo(HaveOccurred())
Expect(cdutil.GetFileContentsFilename).To(Equal(filename))
Expect(contents).To(Equal(cdutil.GetFileContentsContents))
})
})
It("ubuntu get real device path with multiple possible devices", func() {
fs.WriteToFile("/dev/xvda", "")
fs.WriteToFile("/dev/vda", "")
realPath, found := platform.NormalizeDiskPath("/dev/sda")
assert.True(GinkgoT(), found)
assert.Equal(GinkgoT(), "/dev/xvda", realPath)