本文整理匯總了Golang中github.com/cloudfoundry/bosh-utils/blobstore/fakes.FakeBlobstore.GetError方法的典型用法代碼示例。如果您正苦於以下問題:Golang FakeBlobstore.GetError方法的具體用法?Golang FakeBlobstore.GetError怎麽用?Golang FakeBlobstore.GetError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cloudfoundry/bosh-utils/blobstore/fakes.FakeBlobstore
的用法示例。
在下文中一共展示了FakeBlobstore.GetError方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1:
Context("and decompressing the blob fails", func() {
It("returns an error and doesn't remove the target dir", func() {
compressor.DecompressFileToDirErr = fakeError
Expect(fs.FileExists(targetDir)).To(BeTrue())
err := extractor.Extract(blobID, blobSHA1, targetDir)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal("Decompressing compiled package: BlobID: 'fake-blob-id', BlobSHA1: 'fake-sha1': Initial error"))
Expect(fs.FileExists(targetDir)).To(BeTrue())
})
})
})
Context("when getting the blob from the blobstore errors", func() {
BeforeEach(func() {
blobstore.GetError = fakeError
})
It("returns an error", func() {
err := extractor.Extract(blobID, blobSHA1, targetDir)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal("Getting object from blobstore: fake-blob-id: Initial error"))
})
})
Context("when creating the target dir fails", func() {
It("return an error", func() {
fs.MkdirAllError = fakeError
err := extractor.Extract(blobID, blobSHA1, targetDir)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal("Creating target dir: fake-target-dir: Initial error"))
示例2:
Expect(innerBlobstore.GetBlobIDs).To(Equal([]string{"fake-blob-id"}))
Expect(fileName).To(Equal(fixturePath))
})
It("returns error if sha1 does not match", func() {
innerBlobstore.GetFileName = fixturePath
incorrectSha1 := "some-incorrect-sha1"
_, err := sha1VerifiableBlobstore.Get("fake-blob-id", incorrectSha1)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("SHA1 mismatch"))
})
It("returns error if inner blobstore getting fails", func() {
innerBlobstore.GetError = errors.New("fake-get-error")
_, err := sha1VerifiableBlobstore.Get("fake-blob-id", fixtureSHA1)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-get-error"))
})
It("skips sha1 verification and returns without an error if sha1 is empty", func() {
innerBlobstore.GetFileName = fixturePath
fileName, err := sha1VerifiableBlobstore.Get("fake-blob-id", "")
Expect(err).ToNot(HaveOccurred())
Expect(fileName).To(Equal(fixturePath))
})
})
示例3: init
func init() {
Describe("compiledPackageApplier", func() {
var (
packagesBc *fakebc.FakeBundleCollection
blobstore *fakeblob.FakeBlobstore
compressor *fakecmd.FakeCompressor
fs *fakesys.FakeFileSystem
logger boshlog.Logger
applier Applier
)
BeforeEach(func() {
packagesBc = fakebc.NewFakeBundleCollection()
blobstore = fakeblob.NewFakeBlobstore()
compressor = fakecmd.NewFakeCompressor()
fs = fakesys.NewFakeFileSystem()
logger = boshlog.NewLogger(boshlog.LevelNone)
applier = NewCompiledPackageApplier(packagesBc, true, blobstore, compressor, fs, logger)
})
Describe("Prepare & Apply", func() {
var (
pkg models.Package
bundle *fakebc.FakeBundle
)
BeforeEach(func() {
pkg, bundle = buildPkg(packagesBc)
})
ItInstallsPkg := func(act func() error) {
It("returns error when installing package fails", func() {
bundle.InstallError = errors.New("fake-install-error")
err := act()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-install-error"))
})
It("downloads and later cleans up downloaded package blob", func() {
blobstore.GetFileName = "/fake-blobstore-file-name"
err := act()
Expect(err).ToNot(HaveOccurred())
Expect(blobstore.GetBlobIDs[0]).To(Equal("fake-blobstore-id"))
Expect(blobstore.GetFingerprints[0]).To(Equal("fake-blob-sha1"))
// downloaded file is cleaned up
Expect(blobstore.CleanUpFileName).To(Equal("/fake-blobstore-file-name"))
})
It("returns error when downloading package blob fails", func() {
blobstore.GetError = errors.New("fake-get-error")
err := act()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-get-error"))
})
It("decompresses package blob to tmp path and later cleans it up", func() {
fs.TempDirDir = "/fake-tmp-dir"
blobstore.GetFileName = "/fake-blobstore-file-name"
var tmpDirExistsBeforeInstall bool
bundle.InstallCallBack = func() {
tmpDirExistsBeforeInstall = true
}
err := act()
Expect(err).ToNot(HaveOccurred())
Expect(compressor.DecompressFileToDirTarballPaths[0]).To(Equal("/fake-blobstore-file-name"))
Expect(compressor.DecompressFileToDirDirs[0]).To(Equal("/fake-tmp-dir"))
// tmp dir exists before bundle install
Expect(tmpDirExistsBeforeInstall).To(BeTrue())
// tmp dir is cleaned up after install
Expect(fs.FileExists(fs.TempDirDir)).To(BeFalse())
})
It("returns error when temporary directory creation fails", func() {
fs.TempDirError = errors.New("fake-filesystem-tempdir-error")
err := act()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-filesystem-tempdir-error"))
})
It("returns error when decompressing package blob fails", func() {
compressor.DecompressFileToDirErr = errors.New("fake-decompress-error")
err := act()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-decompress-error"))
})
It("installs bundle from decompressed tmp path of a package blob", func() {
fs.TempDirDir = "/fake-tmp-dir"
//.........這裏部分代碼省略.........
示例4:
Expect(blobManager.GetPathCallCount()).To(Equal(1))
Expect(blobManager.GetPathArgsForCall(0)).To(Equal("blobID"))
Expect(innerBlobstore.GetBlobIDs).Should(BeEmpty())
})
})
Describe("when blobManager returns an error", func() {
It("delegates the action of getting the blob to inner blobstore", func() {
blobID := "smurf-4"
digest := boshcrypto.NewDigest("sha1", "smurf-4-sha")
blobManager.GetPathReturns("", errors.New("broken"))
innerBlobstore.GetFileName = "/smurf-file/path"
innerBlobstore.GetError = nil
innerBlobstore.CreateBlobID = "createdBlobID"
filename, err := cascadingBlobstore.Get(blobID, digest)
Expect(blobManager.GetPathCallCount()).To(Equal(1))
Expect(blobManager.GetPathArgsForCall(0)).To(Equal(blobID))
Expect(err).To(BeNil())
Expect(len(innerBlobstore.GetBlobIDs)).To(Equal(1))
Expect(len(innerBlobstore.GetFingerprints)).To(Equal(1))
Expect(innerBlobstore.GetBlobIDs[0]).To(Equal(blobID))
Expect(innerBlobstore.GetFingerprints[0]).To(Equal(digest))
Expect(filename).To(Equal("/smurf-file/path"))
示例5:
"records": [
["fake-ip0", "fake-name0"],
["fake-ip1", "fake-name1"]
]
}`
err := fakeFileSystem.WriteFileString("fake-blobstore-file-path", fakeDNSRecordsString)
Expect(err).ToNot(HaveOccurred())
fakeBlobstore.GetFileName = "fake-blobstore-file-path"
stateFilePath = filepath.Join(fakePlatform.GetDirProvider().BaseDir(), "local_dns_state.json")
})
Context("when local DNS state version is >= Run's version", func() {
BeforeEach(func() {
fakeBlobstore.GetError = errors.New("fake-blobstore-get-error")
})
Context("when the version equals the Run's version", func() {
BeforeEach(func() {
err := fakeFileSystem.WriteFileString(stateFilePath, `{"version": 2}`)
Expect(err).ToNot(HaveOccurred())
fakeFileSystem.WriteFileError = errors.New("fake-write-error")
})
It("returns with no error and does no writes and no gets to blobstore", func() {
_, err := action.Run("fake-blobstore-id", "fake-fingerprint", 2)
Expect(err).ToNot(HaveOccurred())
})
})
示例6: init
func init() {
Describe("renderedJobApplier", func() {
var (
jobsBc *fakebc.FakeBundleCollection
jobSupervisor *fakejobsuper.FakeJobSupervisor
packageApplierProvider *fakepackages.FakeApplierProvider
blobstore *fakeblob.FakeBlobstore
compressor *fakecmd.FakeCompressor
fs *fakesys.FakeFileSystem
applier Applier
)
BeforeEach(func() {
jobsBc = fakebc.NewFakeBundleCollection()
jobSupervisor = fakejobsuper.NewFakeJobSupervisor()
packageApplierProvider = fakepackages.NewFakeApplierProvider()
blobstore = fakeblob.NewFakeBlobstore()
fs = fakesys.NewFakeFileSystem()
compressor = fakecmd.NewFakeCompressor()
logger := boshlog.NewLogger(boshlog.LevelNone)
applier = NewRenderedJobApplier(
jobsBc,
jobSupervisor,
packageApplierProvider,
blobstore,
compressor,
fs,
logger,
)
})
Describe("Prepare & Apply", func() {
var (
job models.Job
bundle *fakebc.FakeBundle
)
BeforeEach(func() {
job, bundle = buildJob(jobsBc)
})
ItInstallsJob := func(act func() error) {
BeforeEach(func() {
fs.TempDirDir = "/fake-tmp-dir"
})
It("returns error when installing job fails", func() {
bundle.InstallError = errors.New("fake-install-error")
err := act()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-install-error"))
})
It("downloads and later cleans up downloaded job template blob", func() {
blobstore.GetFileName = "/fake-blobstore-file-name"
err := act()
Expect(err).ToNot(HaveOccurred())
Expect(blobstore.GetBlobIDs[0]).To(Equal("fake-blobstore-id"))
Expect(blobstore.GetFingerprints[0]).To(Equal(boshcrypto.NewDigest("sha1", "fake-blob-sha1")))
// downloaded file is cleaned up
Expect(blobstore.CleanUpFileName).To(Equal("/fake-blobstore-file-name"))
})
It("returns error when downloading job template blob fails", func() {
blobstore.GetError = errors.New("fake-get-error")
err := act()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("fake-get-error"))
})
It("decompresses job template blob to tmp path and later cleans it up", func() {
blobstore.GetFileName = "/fake-blobstore-file-name"
var tmpDirExistsBeforeInstall bool
bundle.InstallCallBack = func() {
tmpDirExistsBeforeInstall = true
}
err := act()
Expect(err).ToNot(HaveOccurred())
Expect(compressor.DecompressFileToDirTarballPaths[0]).To(Equal("/fake-blobstore-file-name"))
Expect(compressor.DecompressFileToDirDirs[0]).To(Equal("/fake-tmp-dir"))
// tmp dir exists before bundle install
Expect(tmpDirExistsBeforeInstall).To(BeTrue())
// tmp dir is cleaned up after install
Expect(fs.FileExists(fs.TempDirDir)).To(BeFalse())
})
It("returns error when temporary directory creation fails", func() {
fs.TempDirError = errors.New("fake-filesystem-tempdir-error")
//.........這裏部分代碼省略.........