Skip to content

Commit

Permalink
Add test for S3 blobstore
Browse files Browse the repository at this point in the history
  • Loading branch information
Nosmoht committed Mar 26, 2020
1 parent 326dd70 commit 1325c2f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
12 changes: 7 additions & 5 deletions blobstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type Blobstore struct {
AvailableSpaceInBytes int `json:"availableSpaceInBytes"`
BlobCount int `json:"blobCount"`
Name string `json:"name"`
Path string `json:"path"` // only if type File
Path string `json:"path,omitempty"` // only if type File
TotalSizeInBytes int `json:"totalSizeInBytes"`
Type string `json:"type"`

Expand Down Expand Up @@ -114,10 +114,12 @@ func (c client) BlobstoreRead(id string) (*Blobstore, error) {
case BlobstoreTypeFile:
bs.Path = bsDetailed.Path
case BlobstoreTypeS3:
bs.BlobstoreS3AdvancedBucketConnection = bsDetailed.BlobstoreS3AdvancedBucketConnection
bs.BlobstoreS3Bucket = bsDetailed.BlobstoreS3Bucket
bs.BlobstoreS3BucketSecurity = bsDetailed.BlobstoreS3BucketSecurity
bs.BlobstoreS3Encryption = bsDetailed.BlobstoreS3Encryption
bs.BlobstoreS3BucketConfiguration = &BlobstoreS3BucketConfiguration{
BlobstoreS3AdvancedBucketConnection: bsDetailed.BlobstoreS3AdvancedBucketConnection,
BlobstoreS3Bucket: bsDetailed.BlobstoreS3Bucket,
BlobstoreS3BucketSecurity: bsDetailed.BlobstoreS3BucketSecurity,
BlobstoreS3Encryption: bsDetailed.BlobstoreS3Encryption,
}
}
return &bs, nil
}
Expand Down
33 changes: 33 additions & 0 deletions blobstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,36 @@ func TestBlobstoreRead(t *testing.T) {
assert.Equal(t, bsName, bs.Name)
}
}

func TestBlobstoreS3(t *testing.T) {
client := NewClient(getDefaultConfig())

bsName := "test-blobstore-s3"
bsType := BlobstoreTypeS3

bs := Blobstore{
Name: bsName,
Type: bsType,
BlobstoreS3BucketConfiguration: &BlobstoreS3BucketConfiguration{
BlobstoreS3Bucket: &BlobstoreS3Bucket{
Name: getEnv("AWS_BUCKET_NAME", "terraform-provider-nexus-s3-test"),
Region: getEnv("AWS_DEFAULT_REGION", "us-central-1"),
},
BlobstoreS3BucketSecurity: &BlobstoreS3BucketSecurity{
AccessKeyID: getEnv("AWS_ACCESS_KEY_ID", "AWS_ACCESS_KEY_ID must be set"),
SecretAccessKey: getEnv("AWS_SECRET_ACCESS_KEY", "AWS_SECRET_ACCESS_KEY must be set"),
},
},
}

err := client.BlobstoreCreate(bs)
assert.Nil(t, err)

s3BS, err := client.BlobstoreRead(bs.Name)
assert.Nil(t, err)
assert.NotNil(t, s3BS)
assert.Equal(t, BlobstoreTypeS3, s3BS.Type)

err = client.BlobstoreDelete(bs.Name)
assert.Nil(t, err)
}

0 comments on commit 1325c2f

Please sign in to comment.