Ejemplo n.º 1
0
		It("returns error if inner blobstore cleaning up fails", func() {
			innerBlobstore.DeleteErr = errors.New("fake-clean-up-error")

			err := retryableBlobstore.Delete("/some/file")
			Expect(err).To(HaveOccurred())
			Expect(err.Error()).To(ContainSubstring("fake-clean-up-error"))
		})
	})

	Describe("Create", func() {
		Context("when inner blobstore succeeds before maximum number of create tries (first time)", func() {
			It("returns blobID and fingerprint without an error", func() {
				innerBlobstore.CreateBlobID = "fake-blob-id"
				innerBlobstore.CreateFingerprint = "fake-fingerprint"

				blobID, fingerprint, err := retryableBlobstore.Create("fake-file-name")
				Expect(err).ToNot(HaveOccurred())
				Expect(blobID).To(Equal("fake-blob-id"))
				Expect(fingerprint).To(Equal("fake-fingerprint"))

				Expect(innerBlobstore.CreateFileNames).To(Equal([]string{"fake-file-name"}))
			})
		})

		Context("when inner blobstore succeed exactly at maximum number of create tries", func() {
			It("returns blobID and fingerprint without an error", func() {
				innerBlobstore.CreateBlobIDs = []string{"", "", "fake-last-blob-id"}
				innerBlobstore.CreateFingerprints = []string{"", "", "fake-last-fingerprint"}
				innerBlobstore.CreateErrs = []error{
					errors.New("fake-create-err-1"),
					errors.New("fake-create-err-2"),
		})

		It("returns error if inner blobstore cleaning up fails", func() {
			innerBlobstore.DeleteErr = errors.New("fake-clean-up-error")

			err := sha1VerifiableBlobstore.Delete("/some/file")
			Expect(err).To(HaveOccurred())
			Expect(err.Error()).To(ContainSubstring("fake-clean-up-error"))
		})
	})

	Describe("Create", func() {
		It("delegates to inner blobstore to create blob and returns sha1 of returned blob", func() {
			innerBlobstore.CreateBlobID = "fake-blob-id"

			blobID, sha1, err := sha1VerifiableBlobstore.Create(fixturePath)
			Expect(err).ToNot(HaveOccurred())
			Expect(blobID).To(Equal("fake-blob-id"))
			Expect(sha1).To(Equal(fixtureSHA1))

			Expect(innerBlobstore.CreateFileNames[0]).To(Equal(fixturePath))
		})

		It("returns error if inner blobstore blob creation fails", func() {
			innerBlobstore.CreateErr = errors.New("fake-create-error")

			_, _, err := sha1VerifiableBlobstore.Create(fixturePath)
			Expect(err).To(HaveOccurred())
			Expect(err.Error()).To(ContainSubstring("fake-create-error"))
		})
	})
Ejemplo n.º 3
0
		It("returns an error if the inner blobstore fails to clean up", func() {
			innerBlobstore.CleanUpErr = errors.New("error cleaning up")

			err := cascadingBlobstore.CleanUp("randomFile")
			Expect(err).ToNot(BeNil())
			Expect(err.Error()).To(Equal("error cleaning up"))
		})
	})

	Describe("Create", func() {
		It("delegates the action to the inner blobstore", func() {
			innerBlobstore.CreateErr = nil
			innerBlobstore.CreateBlobID = "createBlobId"

			createdBlobID, err := cascadingBlobstore.Create("createdFile")

			Expect(err).To(BeNil())

			Expect(createdBlobID).To(Equal("createBlobId"))

			Expect(innerBlobstore.CreateFileNames).ShouldNot(BeEmpty())
			Expect(len(innerBlobstore.CreateFileNames)).To(Equal(1))
			Expect(innerBlobstore.CreateFileNames[0]).To(Equal("createdFile"))
		})

		It("returns an error if the inner blobstore fails to create", func() {
			innerBlobstore.CreateErr = errors.New("error creating")

			_, err := cascadingBlobstore.Create("createdFile")
Ejemplo n.º 4
0
		It("returns error if inner blobstore cleaning up fails", func() {
			innerBlobstore.DeleteErr = errors.New("fake-clean-up-error")

			err := retryableBlobstore.Delete("/some/file")
			Expect(err).To(HaveOccurred())
			Expect(err.Error()).To(ContainSubstring("fake-clean-up-error"))
		})
	})

	Describe("Create", func() {
		Context("when inner blobstore succeeds before maximum number of create tries (first time)", func() {
			It("returns blobID and fingerprint without an error", func() {
				innerBlobstore.CreateBlobID = "fake-blob-id"

				blobID, err := retryableBlobstore.Create("fake-file-name")
				Expect(err).ToNot(HaveOccurred())
				Expect(blobID).To(Equal("fake-blob-id"))

				Expect(innerBlobstore.CreateFileNames).To(Equal([]string{"fake-file-name"}))
			})
		})

		Context("when inner blobstore succeed exactly at maximum number of create tries", func() {
			It("returns blobID and fingerprint without an error", func() {
				innerBlobstore.CreateBlobIDs = []string{"", "", "fake-last-blob-id"}
				innerBlobstore.CreateErrs = []error{
					errors.New("fake-create-err-1"),
					errors.New("fake-create-err-2"),
					nil,
				}
		})

		It("returns error if inner blobstore cleaning up fails", func() {
			innerBlobstore.DeleteErr = errors.New("fake-clean-up-error")

			err := checksumVerifiableBlobstore.Delete("/some/file")
			Expect(err).To(HaveOccurred())
			Expect(err.Error()).To(ContainSubstring("fake-clean-up-error"))
		})
	})

	Describe("Create", func() {
		It("delegates to inner blobstore to create blob and returns sha1 of returned blob", func() {
			innerBlobstore.CreateBlobID = "fake-blob-id"

			blobID, err := checksumVerifiableBlobstore.Create(fixturePath)
			Expect(err).ToNot(HaveOccurred())
			Expect(blobID).To(Equal("fake-blob-id"))

			Expect(innerBlobstore.CreateFileNames[0]).To(Equal(fixturePath))
		})

		It("returns error if inner blobstore blob creation fails", func() {
			innerBlobstore.CreateErr = errors.New("fake-create-error")

			_, err := checksumVerifiableBlobstore.Create(fixturePath)
			Expect(err).To(HaveOccurred())
			Expect(err.Error()).To(ContainSubstring("fake-create-error"))
		})
	})