forked from ipfs/go-ds-s3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
s3_test.go
68 lines (58 loc) · 1.73 KB
/
s3_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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package s3ds
import (
"fmt"
"os"
"testing"
"time"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/s3"
dstest "github.com/ipfs/go-datastore/test"
)
func TestSuiteLocalS3(t *testing.T) {
// Only run tests when LOCAL_S3 is set, since the tests are only set up for a local S3 endpoint.
// To run tests locally, run `docker-compose up` in this repo in order to get a local S3 running
// on port 9000. Then run `LOCAL_S3=true go test -v ./...` to execute tests.
if _, localS3 := os.LookupEnv("LOCAL_S3"); !localS3 {
t.Skipf("skipping test suit; LOCAL_S3 is not set.")
}
localBucketName, localBucketNameSet := os.LookupEnv("LOCAL_BUCKET_NAME")
if !localBucketNameSet {
localBucketName = fmt.Sprintf("localbucketname%d", time.Now().UnixNano())
}
config := Config{
RegionEndpoint: "http://localhost:9000",
Bucket: localBucketName,
Region: "local",
AccessKey: "test",
SecretKey: "testdslocal",
KeyTransform: "default",
}
s3ds, err := NewS3Datastore(config)
if err != nil {
t.Fatal(err)
}
if err = devMakeBucket(s3ds.S3, localBucketName); err != nil {
t.Fatal(err)
}
t.Run("basic operations", func(t *testing.T) {
dstest.SubtestBasicPutGet(t, s3ds)
})
t.Run("not found operations", func(t *testing.T) {
dstest.SubtestNotFounds(t, s3ds)
})
t.Run("many puts and gets, query", func(t *testing.T) {
dstest.SubtestManyKeysAndQuery(t, s3ds)
})
t.Run("return sizes", func(t *testing.T) {
dstest.SubtestReturnSizes(t, s3ds)
})
}
func devMakeBucket(s3obj *s3.S3, bucketName string) error {
s3obj.DeleteBucket(&s3.DeleteBucketInput{
Bucket: aws.String(bucketName),
})
_, err := s3obj.CreateBucket(&s3.CreateBucketInput{
Bucket: aws.String(bucketName),
})
return err
}