예제 #1
0
//TODO: rename NewBlobstore
func (f blobstoreFactory) Create(blobstoreURL string) (Blobstore, error) {
	blobstoreConfig, err := f.parseBlobstoreURL(blobstoreURL)
	if err != nil {
		return nil, bosherr.WrapError(err, "Creating blobstore config")
	}

	httpClient := bihttpclient.DefaultClient

	davClient := boshdavcli.NewClient(boshdavcliconf.Config{
		Endpoint: fmt.Sprintf("%s/blobs", blobstoreConfig.Endpoint),
		User:     blobstoreConfig.Username,
		Password: blobstoreConfig.Password,
	}, &httpClient)

	return NewBlobstore(davClient, f.uuidGenerator, f.fs, f.logger), nil
}
예제 #2
0
		fakeUUIDGenerator = fakeuuid.NewFakeGenerator()
		fs = fakesys.NewFakeFileSystem()
		logger = boshlog.NewLogger(boshlog.LevelNone)
		httpClient = bihttpclient.DefaultClient

		blobstoreFactory = NewBlobstoreFactory(fakeUUIDGenerator, fs, logger)
	})

	Describe("Create", func() {
		Context("when username and password are provided", func() {
			It("returns the blobstore", func() {
				blobstore, err := blobstoreFactory.Create("https://*****:*****@fake-host:1234")
				Expect(err).ToNot(HaveOccurred())
				davClient := boshdavcli.NewClient(boshdavcliconf.Config{
					Endpoint: "https://fake-host:1234/blobs",
					User:     "******",
					Password: "******",
				}, &httpClient)
				expectedBlobstore := NewBlobstore(davClient, fakeUUIDGenerator, fs, logger)
				Expect(blobstore).To(Equal(expectedBlobstore))
			})
		})

		Context("when URL does not have username and password", func() {
			// This test was added because parsing password is failing when userInfo is missing in URL
			It("returns the blobstore", func() {
				davClient := boshdavcli.NewClient(boshdavcliconf.Config{
					Endpoint: "https://fake-host:1234/blobs",
					User:     "",
					Password: "",
				}, &httpClient)