extend tests
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
6efc858dbd
commit
560cb01564
1
go.mod
1
go.mod
@ -4,6 +4,7 @@ go 1.15
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/gabriel-vasile/mimetype v1.1.2
|
github.com/gabriel-vasile/mimetype v1.1.2
|
||||||
|
github.com/google/uuid v1.1.5
|
||||||
github.com/minio/minio-go/v7 v7.0.7
|
github.com/minio/minio-go/v7 v7.0.7
|
||||||
github.com/unistack-org/micro/v3 v3.2.0
|
github.com/unistack-org/micro/v3 v3.2.0
|
||||||
)
|
)
|
||||||
|
2
s3.go
2
s3.go
@ -69,7 +69,7 @@ func (s *s3Store) Init(opts ...store.Option) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var akey, skey string
|
var akey, skey string
|
||||||
var region string
|
region := "us-east-1"
|
||||||
endpoint := s.endpoint
|
endpoint := s.endpoint
|
||||||
|
|
||||||
if s.opts.Context != nil {
|
if s.opts.Context != nil {
|
||||||
|
32
s3_test.go
32
s3_test.go
@ -6,6 +6,8 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/google/uuid"
|
||||||
|
"github.com/minio/minio-go/v7"
|
||||||
"github.com/unistack-org/micro/v3"
|
"github.com/unistack-org/micro/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -52,22 +54,23 @@ func TestStore(t *testing.T) {
|
|||||||
val := []byte("test")
|
val := []byte("test")
|
||||||
key := "key"
|
key := "key"
|
||||||
|
|
||||||
if err := s.Write(ctx, key, val, WriteBucket("micro-store-s3"), ContentType("text/plain")); err != nil {
|
bucket := "micro-store-s3-" + uuid.New().String()
|
||||||
|
if err := s.Write(ctx, key, val, WriteBucket(bucket), ContentType("text/plain")); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
val = nil
|
val = nil
|
||||||
|
|
||||||
if err := s.Exists(ctx, key, ExistsBucket("micro-store-s3")); err != nil {
|
if err := s.Exists(ctx, key, ExistsBucket(bucket)); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := s.Read(ctx, key, &val, ReadBucket("micro-store-s3")); err != nil {
|
if err := s.Read(ctx, key, &val, ReadBucket(bucket)); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
} else if !bytes.Equal(val, []byte("test")) {
|
} else if !bytes.Equal(val, []byte("test")) {
|
||||||
t.Fatalf("read bytes are not equal %s != %s", val, "test")
|
t.Fatalf("read bytes are not equal %s != %s", val, "test")
|
||||||
}
|
}
|
||||||
|
|
||||||
names, err := s.List(ctx, ListBucket("micro-store-s3"))
|
names, err := s.List(ctx, ListBucket(bucket))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -83,4 +86,25 @@ func TestStore(t *testing.T) {
|
|||||||
t.Fatalf("key not found in %v", names)
|
t.Fatalf("key not found in %v", names)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
objectsCh := make(chan minio.ObjectInfo)
|
||||||
|
minioClient := s.(*s3Store).client
|
||||||
|
// Send object names that are needed to be removed to objectsCh
|
||||||
|
go func() {
|
||||||
|
defer close(objectsCh)
|
||||||
|
// List all objects from a bucket-name with a matching prefix.
|
||||||
|
for object := range minioClient.ListObjects(context.Background(), bucket, minio.ListObjectsOptions{Recursive: true}) {
|
||||||
|
if object.Err != nil {
|
||||||
|
t.Fatal(object.Err)
|
||||||
|
}
|
||||||
|
objectsCh <- object
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
opts := minio.RemoveObjectsOptions{
|
||||||
|
GovernanceBypass: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
for rErr := range minioClient.RemoveObjects(context.Background(), bucket, objectsCh, opts) {
|
||||||
|
t.Fatalf("Error detected during deletion: %v", rErr)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user