-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
bucket_test.go
152 lines (132 loc) · 3.22 KB
/
bucket_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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package cos
import (
"context"
"encoding/xml"
"fmt"
"net/http"
"reflect"
"testing"
)
func TestBucketService_Get(t *testing.T) {
setup()
defer teardown()
opt := &BucketGetOptions{
Prefix: "test",
MaxKeys: 2,
}
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
vs := values{
"prefix": "test",
"max-keys": "2",
}
testFormValues(t, r, vs)
fmt.Fprint(w, `<?xml version='1.0' encoding='utf-8' ?>
<ListBucketResult>
<Name>test-1253846586</Name>
<Prefix>test</Prefix>
<Marker/>
<MaxKeys>2</MaxKeys>
<IsTruncated>true</IsTruncated>
<NextMarker>test/delete.txt</NextMarker>
<Contents>
<Key>test/</Key>
<LastModified>2017-06-09T16:32:25.000Z</LastModified>
<ETag>""</ETag>
<Size>0</Size>
<Owner>
<ID>1253846586</ID>
</Owner>
<StorageClass>STANDARD</StorageClass>
</Contents>
<Contents>
<Key>test/anonymous_get.go</Key>
<LastModified>2017-06-17T15:09:26.000Z</LastModified>
<ETag>"5b7236085f08b3818bfa40b03c946dcc"</ETag>
<Size>8</Size>
<Owner>
<ID>1253846586</ID>
</Owner>
<StorageClass>STANDARD</StorageClass>
</Contents>
</ListBucketResult>`)
})
ref, _, err := client.Bucket.Get(context.Background(), opt)
if err != nil {
t.Fatalf("Bucket.Get returned error: %v", err)
}
want := &BucketGetResult{
XMLName: xml.Name{Local: "ListBucketResult"},
Name: "test-1253846586",
Prefix: "test",
MaxKeys: 2,
IsTruncated: true,
NextMarker: "test/delete.txt",
Contents: []Object{
{
Key: "test/",
LastModified: "2017-06-09T16:32:25.000Z",
ETag: "\"\"",
Size: 0,
Owner: &Owner{
ID: "1253846586",
},
StorageClass: "STANDARD",
},
{
Key: "test/anonymous_get.go",
LastModified: "2017-06-17T15:09:26.000Z",
ETag: "\"5b7236085f08b3818bfa40b03c946dcc\"",
Size: 8,
Owner: &Owner{
ID: "1253846586",
},
StorageClass: "STANDARD",
},
},
}
if !reflect.DeepEqual(ref, want) {
t.Errorf("Bucket.Get returned %+v, want %+v", ref, want)
}
}
func TestBucketService_Put(t *testing.T) {
setup()
defer teardown()
opt := &BucketPutOptions{
XCosACL: "public-read",
}
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
v := new(BucketPutTaggingOptions)
xml.NewDecoder(r.Body).Decode(v)
testMethod(t, r, "PUT")
testHeader(t, r, "x-cos-acl", "public-read")
})
_, err := client.Bucket.Put(context.Background(), opt)
if err != nil {
t.Fatalf("Bucket.Put returned error: %v", err)
}
}
func TestBucketService_Delete(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodDelete)
w.WriteHeader(http.StatusNoContent)
})
_, err := client.Bucket.Delete(context.Background())
if err != nil {
t.Fatalf("Bucket.Delete returned error: %v", err)
}
}
func TestBucketService_Head(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodHead)
w.WriteHeader(http.StatusOK)
})
_, err := client.Bucket.Head(context.Background())
if err != nil {
t.Fatalf("Bucket.Head returned error: %v", err)
}
}