forked from gomods/athens
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_suite.go
53 lines (46 loc) · 1.5 KB
/
test_suite.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package minio
import (
"github.com/gobuffalo/suite"
"github.com/gomods/athens/pkg/storage"
minio "github.com/minio/minio-go"
)
// TestSuite implements storage.TestSuite interface
type TestSuite struct {
*suite.Model
storage storage.Backend
endpoint, accessKeyID, secretAccessKey, bucketName string
}
// NewTestSuite creates a common test suite
func NewTestSuite(model *suite.Model) (storage.TestSuite, error) {
endpoint := "127.0.0.1:9000"
bucketName := "gomods"
accessKeyID := "minio"
secretAccessKey := "minio123"
minioStorage, err := NewStorage(endpoint, accessKeyID, secretAccessKey, bucketName, false)
return &TestSuite{
storage: minioStorage,
Model: model,
endpoint: endpoint,
bucketName: bucketName,
accessKeyID: accessKeyID,
secretAccessKey: secretAccessKey,
}, err
}
// Storage retrieves initialized storage backend
func (ts *TestSuite) Storage() storage.Backend {
return ts.storage
}
// StorageHumanReadableName retrieves readable identifier of the storage
func (ts *TestSuite) StorageHumanReadableName() string {
return "Minio"
}
// Cleanup tears down test
func (ts *TestSuite) Cleanup() {
minioClient, _ := minio.New(ts.endpoint, ts.accessKeyID, ts.secretAccessKey, false)
doneCh := make(chan struct{})
defer close(doneCh)
objectCh := minioClient.ListObjectsV2(ts.bucketName, "", true, doneCh)
for object := range objectCh {
ts.Require().NoError(minioClient.RemoveObject(ts.bucketName, object.Key))
}
}