當前位置: 首頁>>代碼示例>>Golang>>正文


Golang FakeBlobstore.GetFileName方法代碼示例

本文整理匯總了Golang中github.com/cloudfoundry/bosh-utils/blobstore/fakes.FakeBlobstore.GetFileName方法的典型用法代碼示例。如果您正苦於以下問題:Golang FakeBlobstore.GetFileName方法的具體用法?Golang FakeBlobstore.GetFileName怎麽用?Golang FakeBlobstore.GetFileName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/cloudfoundry/bosh-utils/blobstore/fakes.FakeBlobstore的用法示例。


在下文中一共展示了FakeBlobstore.GetFileName方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1:

		blobID    string
		blobSHA1  string
		fileName  string
		fakeError error
	)

	BeforeEach(func() {
		blobstore = fakeblobstore.NewFakeBlobstore()
		targetDir = "fake-target-dir"
		compressor = fakecmd.NewFakeCompressor()
		logger = boshlog.NewLogger(boshlog.LevelNone)
		fs = fakesys.NewFakeFileSystem()
		blobID = "fake-blob-id"
		blobSHA1 = "fake-sha1"
		fileName = "tarball.tgz"
		blobstore.GetFileName = fileName
		fakeError = errors.New("Initial error")

		extractor = NewExtractor(fs, compressor, blobstore, logger)
	})

	Describe("Cleanup", func() {
		BeforeEach(func() {
			err := extractor.Extract(blobID, blobSHA1, targetDir)
			Expect(err).ToNot(HaveOccurred())
		})

		It("deletes the extracted temp file", func() {
			Expect(fs.FileExists(targetDir)).To(BeTrue())
			err := extractor.Cleanup(blobID, targetDir)
			Expect(err).ToNot(HaveOccurred())
開發者ID:mattcui,項目名稱:bosh-init,代碼行數:31,代碼來源:extractor_test.go

示例2:

		fixtureSHA1 = "da39a3ee5e6b4b0d3255bfef95601890afd80709"
	)

	var (
		innerBlobstore          *fakeblob.FakeBlobstore
		sha1VerifiableBlobstore boshblob.Blobstore
	)

	BeforeEach(func() {
		innerBlobstore = &fakeblob.FakeBlobstore{}
		sha1VerifiableBlobstore = boshblob.NewSHA1VerifiableBlobstore(innerBlobstore)
	})

	Describe("Get", func() {
		It("returns without an error if sha1 matches", func() {
			innerBlobstore.GetFileName = fixturePath

			fileName, err := sha1VerifiableBlobstore.Get("fake-blob-id", fixtureSHA1)
			Expect(err).ToNot(HaveOccurred())

			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"))
開發者ID:EMC-CMD,項目名稱:bosh-agent,代碼行數:31,代碼來源:sha1_verifiable_blobstore_test.go

示例3:

	var (
		innerBlobstore     *fakeblob.FakeBlobstore
		logger             boshlog.Logger
		retryableBlobstore boshblob.Blobstore
	)

	BeforeEach(func() {
		innerBlobstore = &fakeblob.FakeBlobstore{}
		logger = boshlog.NewLogger(boshlog.LevelNone)
		retryableBlobstore = boshblob.NewRetryableBlobstore(innerBlobstore, 3, logger)
	})

	Describe("Get", func() {
		Context("when inner blobstore succeeds before maximum number of get tries (first time)", func() {
			It("returns path without an error", func() {
				innerBlobstore.GetFileName = "fake-path"

				path, err := retryableBlobstore.Get("fake-blob-id", "fake-fingerprint")
				Expect(err).ToNot(HaveOccurred())
				Expect(path).To(Equal("fake-path"))

				Expect(innerBlobstore.GetBlobIDs).To(Equal([]string{"fake-blob-id"}))
				Expect(innerBlobstore.GetFingerprints).To(Equal([]string{"fake-fingerprint"}))
			})
		})

		Context("when inner blobstore succeed exactly at maximum number of get tries", func() {
			It("returns path without an error", func() {
				innerBlobstore.GetFileNames = []string{"", "", "fake-last-path"}
				innerBlobstore.GetErrs = []error{
					errors.New("fake-get-err-1"),
開發者ID:jianqiu,項目名稱:bosh-agent,代碼行數:31,代碼來源:retryable_blobstore_test.go

示例4: 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"
//.........這裏部分代碼省略.........
開發者ID:EMC-CMD,項目名稱:bosh-agent,代碼行數:101,代碼來源:compiled_package_applier_test.go

示例5:

				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))
開發者ID:mattcui,項目名稱:bosh-agent,代碼行數:29,代碼來源:cascading_blobstore_test.go

示例6:

	Context("when sync_dns is recieved", func() {
		Context("when blobstore contains DNS records", func() {
			BeforeEach(func() {
				fakeDNSRecordsString := `
				{
					"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"
			})

			It("accesses the blobstore and fetches DNS records", func() {
				response, err := syncDNS.Run("fake-blobstore-id", "fake-fingerprint")
				Expect(err).ToNot(HaveOccurred())
				Expect(response).To(Equal("synced"))

				Expect(fakeBlobstore.GetBlobIDs).To(ContainElement("fake-blobstore-id"))
				Expect(fakeBlobstore.GetFingerprints).To(ContainElement("fake-fingerprint"))

				Expect(fakeBlobstore.GetError).ToNot(HaveOccurred())
				Expect(fakeBlobstore.GetFileName).ToNot(Equal(""))
			})

			It("reads the DNS records from the blobstore file", func() {
開發者ID:mattcui,項目名稱:bosh-init,代碼行數:30,代碼來源:sync_dns_test.go

示例7:

		var stateFilePath string

		BeforeEach(func() {
			fakeDNSRecordsString := `
							{
								"version": 2,
								"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")
				})
開發者ID:mattcui,項目名稱:bosh-agent,代碼行數:31,代碼來源:sync_dns_test.go

示例8: 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")

//.........這裏部分代碼省略.........
開發者ID:mattcui,項目名稱:bosh-agent,代碼行數:101,代碼來源:rendered_job_applier_test.go


注:本文中的github.com/cloudfoundry/bosh-utils/blobstore/fakes.FakeBlobstore.GetFileName方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。