forked from rclone/gofakes3
-
Notifications
You must be signed in to change notification settings - Fork 1
/
option_autobucket_test.go
136 lines (116 loc) · 2.93 KB
/
option_autobucket_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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package gofakes3_test
import (
"bytes"
"testing"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/alist-org/gofakes3"
)
const autoBucket = "autobucket"
func newAutoBucketTestServer(t *testing.T) *testServer {
t.Helper()
return newTestServer(t,
withoutInitialBuckets(),
withFakerOptions(gofakes3.WithAutoBucket(true)))
}
func TestAutoBucketPutObject(t *testing.T) {
autoSrv := newAutoBucketTestServer(t)
defer autoSrv.Close()
svc := autoSrv.s3Client()
_, err := svc.PutObject(&s3.PutObjectInput{
Bucket: aws.String(autoBucket),
Key: aws.String("object"),
Body: bytes.NewReader([]byte("hello")),
})
if err != nil {
t.Fatal(err)
}
autoSrv.assertObject(autoBucket, "object", nil, "hello")
}
func TestAutoBucketGetObject(t *testing.T) {
ts := newAutoBucketTestServer(t)
defer ts.Close()
svc := ts.s3Client()
_, err := svc.GetObject(&s3.GetObjectInput{
Bucket: aws.String(autoBucket),
Key: aws.String("object"),
})
if !hasErrorCode(err, gofakes3.ErrNoSuchKey) {
t.Fatal(err)
}
}
func TestAutoBucketDeleteObject(t *testing.T) {
ts := newAutoBucketTestServer(t)
defer ts.Close()
svc := ts.s3Client()
_, err := svc.DeleteObject(&s3.DeleteObjectInput{
Bucket: aws.String(autoBucket),
Key: aws.String("object"),
})
if err != nil {
t.Fatal(err)
}
}
func TestAutoBucketGetBucketLocation(t *testing.T) {
autoSrv := newAutoBucketTestServer(t)
defer autoSrv.Close()
svc := autoSrv.s3Client()
_, err := svc.GetBucketLocation(&s3.GetBucketLocationInput{
Bucket: aws.String(autoBucket),
})
if err != nil {
t.Fatal(err)
}
}
func TestAutoBucketDeleteObjectVersion(t *testing.T) {
ts := newAutoBucketTestServer(t)
defer ts.Close()
svc := ts.s3Client()
_, err := svc.DeleteObject(&s3.DeleteObjectInput{
Bucket: aws.String(autoBucket),
Key: aws.String("object"),
VersionId: aws.String("version"),
})
if err != nil {
t.Fatal(err)
}
}
func TestAutoBucketDeleteObjectsVersion(t *testing.T) {
ts := newAutoBucketTestServer(t)
defer ts.Close()
svc := ts.s3Client()
_, err := svc.DeleteObjects(&s3.DeleteObjectsInput{
Delete: &s3.Delete{
Objects: []*s3.ObjectIdentifier{
{Key: aws.String("object1"), VersionId: aws.String("version1")},
{Key: aws.String("object2"), VersionId: aws.String("version2")},
},
},
Bucket: aws.String(autoBucket),
})
if err != nil {
t.Fatal(err)
}
}
func TestAutoBucketListMultipartUploads(t *testing.T) {
ts := newAutoBucketTestServer(t)
defer ts.Close()
svc := ts.s3Client()
_, err := svc.ListMultipartUploads(&s3.ListMultipartUploadsInput{
Bucket: aws.String(autoBucket),
})
if !hasErrorCode(err, gofakes3.ErrNoSuchUpload) {
t.Fatal(err)
}
}
func TestAutoBucketGetBucketVersioning(t *testing.T) {
ts := newAutoBucketTestServer(t)
defer ts.Close()
svc := ts.s3Client()
_, err := svc.GetBucketVersioning(&s3.GetBucketVersioningInput{
Bucket: aws.String(autoBucket),
})
if err != nil {
t.Fatal(err)
}
}