forked from cosmo0920/fluent-bit-go-s3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
s3_test.go
103 lines (90 loc) · 4.5 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package main
import (
"errors"
"github.com/stretchr/testify/assert"
"testing"
"time"
)
func TestGetS3ConfigStaticCredentials(t *testing.T) {
conf, err := getS3Config("exampleaccessID", "examplesecretkey", "", "exampleprefix", "examplebucket", "exampleregion", "", "", "", "", "")
if err != nil {
t.Fatalf("failed test %#v", err)
}
assert.Equal(t, "examplebucket", *conf.bucket, "Specify bucket name")
assert.Equal(t, "exampleprefix", *conf.s3prefix, "Specify s3prefix name")
assert.NotNil(t, conf.credentials, "credentials not to be nil")
assert.Equal(t, "exampleregion", *conf.region, "Specify s3prefix name")
assert.Equal(t, plainTextFormat, conf.compress, "Specify compression method")
assert.Equal(t, false, conf.autoCreateBucket, "Specify true/false")
}
func TestGetS3ConfigSharedCredentials(t *testing.T) {
s3Creds = &testS3Credential{}
conf, err := getS3Config("", "", "examplecredentials", "exampleprefix", "examplebucket", "exampleregion", "", "", "", "", "")
if err != nil {
t.Fatalf("failed test %#v", err)
}
assert.Equal(t, "examplebucket", *conf.bucket, "Specify bucket name")
assert.Equal(t, "exampleprefix", *conf.s3prefix, "Specify s3prefix name")
assert.NotNil(t, conf.credentials, "credentials not to be nil")
assert.Equal(t, "exampleregion", *conf.region, "Specify s3prefix name")
assert.Equal(t, plainTextFormat, conf.compress, "Specify compression method")
assert.Equal(t, false, conf.autoCreateBucket, "Specify true/false")
}
func TestGetS3ConfigCompression(t *testing.T) {
s3Creds = &testS3Credential{}
conf, err := getS3Config("", "", "examplecredentials", "exampleprefix", "examplebucket", "exampleregion", "gzip", "", "", "", "")
if err != nil {
t.Fatalf("failed test %#v", err)
}
assert.Equal(t, "examplebucket", *conf.bucket, "Specify bucket name")
assert.Equal(t, "exampleprefix", *conf.s3prefix, "Specify s3prefix name")
assert.NotNil(t, conf.credentials, "credentials not to be nil")
assert.Equal(t, "exampleregion", *conf.region, "Specify s3prefix name")
assert.Equal(t, gzipFormat, conf.compress, "Specify compression method")
assert.Equal(t, false, conf.autoCreateBucket, "Specify true/false")
}
func TestGetS3ConfigEndpoint(t *testing.T) {
s3Creds = &testS3Credential{}
conf, err := getS3Config("", "", "examplecredentials", "exampleprefix", "examplebucket", "exampleregion", "gzip", "http://localhost:9000", "false", "", "")
if err != nil {
t.Fatalf("failed test %#v", err)
}
assert.Equal(t, "examplebucket", *conf.bucket, "Specify bucket name")
assert.Equal(t, "exampleprefix", *conf.s3prefix, "Specify s3prefix name")
assert.NotNil(t, conf.credentials, "credentials not to be nil")
assert.Equal(t, "exampleregion", *conf.region, "Specify s3prefix name")
assert.Equal(t, gzipFormat, conf.compress, "Specify compression method")
assert.Equal(t, "http://localhost:9000", conf.endpoint, "Specify correct endpoint")
assert.Equal(t, false, conf.autoCreateBucket, "Specify true/false")
}
func TestGetS3ConfigInvalidEndpoint(t *testing.T) {
s3Creds = &testS3Credential{}
_, err := getS3Config("", "", "examplecredentials", "exampleprefix", "examplebucket", "exampleregion", "gzip", "https://your-bucketname.s3.amazonaws.com", "false", "", "")
if err != nil {
expected := errors.New("Endpoint is not supported for AWS S3. This parameter is intended for S3 compatible services. Use Region instead.")
assert.Equal(t, expected, err)
}
}
func TestGetS3ConfigTimeZone(t *testing.T) {
s3Creds = &testS3Credential{}
conf, err := getS3Config("", "", "examplecredentials", "exampleprefix", "examplebucket", "exampleregion", "gzip", "", "", "", "Asia/Tokyo")
if err != nil {
t.Fatalf("failed test %#v", err)
}
assert.Equal(t, "examplebucket", *conf.bucket, "Specify bucket name")
assert.Equal(t, "exampleprefix", *conf.s3prefix, "Specify s3prefix name")
assert.NotNil(t, conf.credentials, "credentials not to be nil")
assert.Equal(t, "exampleregion", *conf.region, "Specify s3prefix name")
assert.Equal(t, gzipFormat, conf.compress, "Specify compression method")
assert.Equal(t, false, conf.autoCreateBucket, "Specify true/false")
loc, _ := time.LoadLocation("Asia/Tokyo")
assert.Equal(t, loc, conf.location, "Specify valid TimeZone")
}
func TestGetS3ConfigInvalidTimeZone(t *testing.T) {
s3Creds = &testS3Credential{}
_, err := getS3Config("", "", "examplecredentials", "exampleprefix", "examplebucket", "exampleregion", "gzip", "", "", "", "Asia/Nonexistent")
if err != nil {
expected := errors.New("invalid timeZone: unknown time zone Asia/Nonexistent")
assert.Equal(t, expected, err)
}
}