-
Notifications
You must be signed in to change notification settings - Fork 490
/
minio_test.go
51 lines (43 loc) · 1.03 KB
/
minio_test.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
package minio
import (
"os"
"testing"
"github.com/gomods/athens/pkg/config"
"github.com/gomods/athens/pkg/storage/compliance"
)
func TestBackend(t *testing.T) {
backend := getStorage(t)
compliance.RunTests(t, backend, backend.clear)
}
func BenchmarkBackend(b *testing.B) {
backend := getStorage(b)
compliance.RunBenchmarks(b, backend, backend.clear)
}
func (s *storageImpl) clear() error {
objectCh, _ := s.minioCore.ListObjectsV2(s.bucketName, "", "", false, "", 0, "")
for _, object := range objectCh.Contents {
if object.Err != nil {
return object.Err
}
if err := s.minioClient.RemoveObject(s.bucketName, object.Key); err != nil {
return err
}
}
return nil
}
func getStorage(t testing.TB) *storageImpl {
url := os.Getenv("ATHENS_MINIO_ENDPOINT")
if url == "" {
t.SkipNow()
}
backend, err := NewStorage(&config.MinioConfig{
Endpoint: url,
Key: "minio",
Secret: "minio123",
Bucket: "gomods",
}, config.GetTimeoutDuration(300))
if err != nil {
t.Fatal(err)
}
return backend.(*storageImpl)
}