Exemple #1
0
func TestExternalCleanUp(t *testing.T) {
	fs, runner, uuidGen, configPath := getExternalBlobstoreDependencies()
	blobstore := NewExternalBlobstore("fake-provider", map[string]string{}, fs, runner, uuidGen, configPath)

	file, err := fs.TempFile("bosh-blobstore-external-TestCleanUp")
	assert.NoError(t, err)
	fileName := file.Name()

	defer fs.RemoveAll(fileName)

	err = blobstore.CleanUp(fileName)
	assert.NoError(t, err)
	assert.False(t, fs.FileExists(fileName))
}
Exemple #2
0
func init() {
	Describe("Testing with Ginkgo", func() {
		It("external validate writes config file", func() {
			fs, runner, uuidGen, configPath := getExternalBlobstoreDependencies()

			options := map[string]string{"fake-key": "fake-value"}

			blobstore := NewExternalBlobstore("fake-provider", options, fs, runner, uuidGen, configPath)

			runner.CommandExistsValue = true
			assert.NoError(GinkgoT(), blobstore.Validate())

			s3CliConfig, err := fs.ReadFileString(configPath)
			Expect(err).ToNot(HaveOccurred())

			expectedJson := map[string]string{"fake-key": "fake-value"}
			boshassert.MatchesJsonString(GinkgoT(), expectedJson, s3CliConfig)
		})
		It("external validate errors when command not in path", func() {

			fs, runner, uuidGen, configPath := getExternalBlobstoreDependencies()

			options := map[string]string{}

			blobstore := NewExternalBlobstore("fake-provider", options, fs, runner, uuidGen, configPath)

			assert.Error(GinkgoT(), blobstore.Validate())
		})
		It("external get", func() {

			fs, runner, uuidGen, configPath := getExternalBlobstoreDependencies()
			blobstore := NewExternalBlobstore("fake-provider", map[string]string{}, fs, runner, uuidGen, configPath)

			tempFile, err := fs.TempFile("bosh-blobstore-external-TestGet")
			Expect(err).ToNot(HaveOccurred())

			fs.ReturnTempFile = tempFile
			defer fs.RemoveAll(tempFile.Name())

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

			Expect(1).To(Equal(len(runner.RunCommands)))
			assert.Equal(GinkgoT(), []string{
				"bosh-blobstore-fake-provider", "-c", configPath, "get",
				"fake-blob-id",
				tempFile.Name(),
			}, runner.RunCommands[0])

			Expect(fileName).To(Equal(tempFile.Name()))
			Expect(fs.FileExists(tempFile.Name())).To(BeTrue())
		})
		It("external get errs when temp file create errs", func() {

			fs, runner, uuidGen, configPath := getExternalBlobstoreDependencies()
			blobstore := NewExternalBlobstore("fake-provider", map[string]string{}, fs, runner, uuidGen, configPath)

			fs.TempFileError = errors.New("fake-error")

			fileName, err := blobstore.Get("fake-blob-id", "")
			Expect(err).To(HaveOccurred())
			Expect(err.Error()).To(ContainSubstring("fake-error"))

			assert.Empty(GinkgoT(), fileName)
		})
		It("external get errs when external cli errs", func() {

			fs, runner, uuidGen, configPath := getExternalBlobstoreDependencies()
			blobstore := NewExternalBlobstore("fake-provider", map[string]string{}, fs, runner, uuidGen, configPath)

			tempFile, err := fs.TempFile("bosh-blobstore-external-TestGetErrsWhenExternalCliErrs")
			Expect(err).ToNot(HaveOccurred())

			fs.ReturnTempFile = tempFile
			defer fs.RemoveAll(tempFile.Name())

			expectedCmd := []string{
				"bosh-blobstore-fake-provider", "-c", configPath, "get",
				"fake-blob-id",
				tempFile.Name(),
			}
			runner.AddCmdResult(strings.Join(expectedCmd, " "), fakesys.FakeCmdResult{Error: errors.New("fake-error")})

			fileName, err := blobstore.Get("fake-blob-id", "")
			Expect(err).To(HaveOccurred())
			Expect(err.Error()).To(ContainSubstring("fake-error"))

			assert.Empty(GinkgoT(), fileName)
			Expect(fs.FileExists(tempFile.Name())).To(BeFalse())
		})
		It("external clean up", func() {

			fs, runner, uuidGen, configPath := getExternalBlobstoreDependencies()
			blobstore := NewExternalBlobstore("fake-provider", map[string]string{}, fs, runner, uuidGen, configPath)

			file, err := fs.TempFile("bosh-blobstore-external-TestCleanUp")
			Expect(err).ToNot(HaveOccurred())
			fileName := file.Name()

			defer fs.RemoveAll(fileName)

			err = blobstore.CleanUp(fileName)
			Expect(err).ToNot(HaveOccurred())
			Expect(fs.FileExists(fileName)).To(BeFalse())
		})
		It("external create", func() {

			fileName := "../../../fixtures/some.config"
			expectedPath, _ := filepath.Abs(fileName)

			fs, runner, uuidGen, configPath := getExternalBlobstoreDependencies()
			blobstore := NewExternalBlobstore("fake-provider", map[string]string{}, fs, runner, uuidGen, configPath)

			uuidGen.GeneratedUuid = "some-uuid"

			blobId, fingerprint, err := blobstore.Create(fileName)
			Expect(err).ToNot(HaveOccurred())
			Expect(blobId).To(Equal("some-uuid"))
			assert.Empty(GinkgoT(), fingerprint)

			Expect(1).To(Equal(len(runner.RunCommands)))
			assert.Equal(GinkgoT(), []string{
				"bosh-blobstore-fake-provider", "-c", configPath, "put",
				expectedPath, "some-uuid",
			}, runner.RunCommands[0])
		})
	})
}