Fixed Minio NewStorage to return the MakeBucket error instead of the (#1302)

Bucket exists error.  See #1295
This commit is contained in:
James Naftel
2019-07-16 18:23:04 -04:00
committed by Aaron Schlesinger
parent 7de77889ad
commit 33d01b1a7a
2 changed files with 63 additions and 2 deletions
+3 -2
View File
@@ -39,8 +39,9 @@ func NewStorage(conf *config.MinioConfig, timeout time.Duration) (storage.Backen
err = minioClient.MakeBucket(bucketName, region)
if err != nil {
// Check to see if we already own this bucket
exists, err := minioClient.BucketExists(bucketName)
if err == nil && !exists {
exists, _ := minioClient.BucketExists(bucketName)
if !exists {
// MakeBucket Error takes priority
return nil, errors.E(op, err)
}
}
+60
View File
@@ -13,6 +13,66 @@ func TestBackend(t *testing.T) {
compliance.RunTests(t, backend, backend.clear)
}
// TestNewStorageExists tests the logic around MakeBucket and BucketExists
func TestNewStorageExists(t *testing.T) {
url := os.Getenv("ATHENS_MINIO_ENDPOINT")
if url == "" {
t.SkipNow()
}
tests := []struct {
name string
deleteBucket bool
}{
{"testbucket", false}, // test creation
{"testbucket", true}, // test exists
}
for _, test := range tests {
backend, err := NewStorage(&config.MinioConfig{
Endpoint: url,
Key: "minio",
Secret: "minio123",
Bucket: test.name,
}, config.GetTimeoutDuration(300))
if err != nil {
t.Fatalf("TestNewStorageExists failed for bucketname: %s, error: %v\n", test.name, err)
}
client, ok := backend.(*storageImpl)
if test.deleteBucket && ok {
client.minioClient.RemoveBucket(test.name)
}
}
}
// TestNewStorageError tests the logic around MakeBucket and BucketExists
// MakeBucket uses a strict naming path in minio while BucketExists does not.
// To ensure both paths are tested, there is a strict path error using the
// "_" and a non strict error using less than 3 characters
func TestNewStorageError(t *testing.T) {
url := os.Getenv("ATHENS_MINIO_ENDPOINT")
if url == "" {
t.SkipNow()
}
// "_" is not allowed in a bucket name
// bucket name must be bigger than 3
tests := []string{"test_bucket", "1"}
for _, bucketName := range tests {
_, err := NewStorage(&config.MinioConfig{
Endpoint: url,
Key: "minio",
Secret: "minio123",
Bucket: bucketName,
}, config.GetTimeoutDuration(300))
if err == nil {
t.Fatalf("TestNewStorageError failed for bucketname: %s\n", bucketName)
}
}
}
func BenchmarkBackend(b *testing.B) {
backend := getStorage(b)
compliance.RunBenchmarks(b, backend, backend.clear)