-
Notifications
You must be signed in to change notification settings - Fork 92
/
bucket_accelerate_test.go
79 lines (68 loc) · 1.7 KB
/
bucket_accelerate_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
package cos
import (
"context"
"encoding/xml"
"fmt"
"net/http"
"reflect"
"testing"
)
func TestBucketService_GetAccelerate(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
vs := values{
"accelerate": "",
}
testFormValues(t, r, vs)
fmt.Fprint(w, `<AccelerateConfiguration>
<Status>Enabled</Status>
<Type>COS</Type>
</AccelerateConfiguration>`)
})
res, _, err := client.Bucket.GetAccelerate(context.Background())
if err != nil {
t.Fatalf("Bucket.GetAccelerate returned error %v", err)
}
want := &BucketGetAccelerateResult{
XMLName: xml.Name{Local: "AccelerateConfiguration"},
Status: "Enabled",
Type: "COS",
}
if !reflect.DeepEqual(res, want) {
t.Errorf("Bucket.GetAccelerate returned %+v, want %+v", res, want)
}
}
func TestBucketService_PutAccelerate(t *testing.T) {
setup()
defer teardown()
opt := &BucketPutAccelerateOptions{
XMLName: xml.Name{Local: "AccelerateConfiguration"},
Status: "Enabled",
Type: "COS",
}
rt := 0
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PUT")
vs := values{
"accelerate": "",
}
testFormValues(t, r, vs)
body := new(BucketPutAccelerateOptions)
xml.NewDecoder(r.Body).Decode(body)
want := opt
want.XMLName = xml.Name{Local: "AccelerateConfiguration"}
if !reflect.DeepEqual(body, want) {
t.Errorf("Bucket.PutAccelerate request\n body: %+v\n, want %+v\n", body, want)
}
rt++
if rt < 3 {
w.WriteHeader(http.StatusBadGateway)
}
})
_, err := client.Bucket.PutAccelerate(context.Background(), opt)
if err != nil {
t.Fatalf("Bucket.PutAccelerate returned error: %v", err)
}
}