Esempio n. 1
0
					Expect(err).ToNot(HaveOccurred())

					Expect(fakeStage.PerformCalls[0].Name).To(Equal("Downloading fake-description"))
					Expect(fakeStage.PerformCalls[0].SkipError.Error()).To(Equal("Found in local cache: Already downloaded"))
				})
			})

			Context("when tarball is not present in cache", func() {
				var (
					tempDownloadFilePath string
				)

				BeforeEach(func() {
					tempDownloadFile, err := ioutil.TempFile("", "temp-download-file")
					Expect(err).ToNot(HaveOccurred())
					fs.ReturnTempFile = tempDownloadFile
					tempDownloadFilePath = tempDownloadFile.Name()
					sha1Calculator.SetCalculateBehavior(map[string]fakebicrypto.CalculateInput{
						tempDownloadFilePath: {Sha1: "fake-sha1"},
					})
				})

				AfterEach(func() {
					os.RemoveAll(tempDownloadFilePath)
				})

				Context("when downloading succeds", func() {
					BeforeEach(func() {
						httpClient.SetGetBehavior("fake-body", 200, nil)
						httpClient.SetGetBehavior("fake-body", 200, nil)
						httpClient.SetGetBehavior("fake-body", 200, nil)
Esempio n. 2
0
			blobstore = NewLocalBlobstore(fs, uuidGen, options)

			err := blobstore.Validate()
			Expect(err).To(HaveOccurred())
			Expect(err.Error()).To(ContainSubstring("blobstore_path must be a string"))
		})
	})

	Describe("Get", func() {
		It("fetches the local blob contents", 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("errs when temp file create errs", func() {
			fs.TempFileError = errors.New("fake-error")

			fileName, err := blobstore.Get("fake-blob-id", "")
			Expect(err).To(HaveOccurred())
Esempio n. 3
0
		blobstore         Blobstore
	)

	BeforeEach(func() {
		fakeDavClient = fakeboshdavcli.NewFakeClient()
		fakeUUIDGenerator = fakeuuid.NewFakeGenerator()
		fs = fakesys.NewFakeFileSystem()
		logger := boshlog.NewLogger(boshlog.LevelNone)

		blobstore = NewBlobstore(fakeDavClient, fakeUUIDGenerator, fs, logger)
	})

	Describe("Get", func() {
		BeforeEach(func() {
			fakeFile := fakesys.NewFakeFile("fake-destination-path", fs)
			fs.ReturnTempFile = fakeFile
		})

		It("gets the blob from the blobstore", func() {
			fakeDavClient.GetContents = ioutil.NopCloser(strings.NewReader("fake-content"))

			localBlob, err := blobstore.Get("fake-blob-id")
			Expect(err).ToNot(HaveOccurred())
			defer localBlob.DeleteSilently()

			Expect(fakeDavClient.GetPath).To(Equal("fake-blob-id"))
		})

		It("saves the blob to the destination path", func() {
			fakeDavClient.GetContents = ioutil.NopCloser(strings.NewReader("fake-content"))