-
Notifications
You must be signed in to change notification settings - Fork 91
/
bucket_object_lock_test.go
143 lines (123 loc) · 3.37 KB
/
bucket_object_lock_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
package cos
import (
"context"
"encoding/xml"
"fmt"
"net/http"
"reflect"
"testing"
)
func TestBucketService_GetObjectLockConfiguration(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
vs := values{
"object-lock": "",
}
testFormValues(t, r, vs)
fmt.Fprint(w, `<ObjectLockConfiguration>
<ObjectLockEnabled>Enabled</ObjectLockEnabled>
<Rule>
<DefaultRetention>
<Days>30</Days>
</DefaultRetention>
</Rule>
</ObjectLockConfiguration>`)
})
res, _, err := client.Bucket.GetObjectLockConfiguration(context.Background())
if err != nil {
t.Fatalf("Bucket.GetObjectLockConfiguration returned error %v", err)
}
want := &BucketGetObjectLockResult{
XMLName: xml.Name{Local: "ObjectLockConfiguration"},
ObjectLockEnabled: "Enabled",
Rule: &ObjectLockRule{
Days: 30,
},
}
if !reflect.DeepEqual(res, want) {
t.Errorf("Bucket.GetObjectLockConfiguration returned %+v, want %+v", res, want)
}
}
func TestBucketService_PutObjectLockConfiguration(t *testing.T) {
setup()
defer teardown()
opt := &BucketPutObjectLockOptions{
ObjectLockEnabled: "Enabled",
Rule: &ObjectLockRule{
Days: 30,
},
}
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PUT")
vs := values{
"object-lock": "",
}
testFormValues(t, r, vs)
body := new(BucketPutObjectLockOptions)
xml.NewDecoder(r.Body).Decode(body)
want := opt
want.XMLName = xml.Name{Local: "ObjectLockConfiguration"}
if !reflect.DeepEqual(body, want) {
t.Errorf("Bucket.PutObjectLockConfiguration request\n body: %+v\nwant %+v\n", body, want)
}
})
_, err := client.Bucket.PutObjectLockConfiguration(context.Background(), opt)
if err != nil {
t.Fatalf("Bucket.PutObjectLockConfiguration returned error: %v", err)
}
}
func TestBucketService_GetRetention(t *testing.T) {
setup()
defer teardown()
key := "example"
mux.HandleFunc("/example", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
vs := values{
"retention": "",
}
testFormValues(t, r, vs)
fmt.Fprint(w, `<Retention>
<RetainUntilDate>2023-05-18T07:19:55.000Z</RetainUntilDate>
</Retention>`)
})
res, _, err := client.Object.GetRetention(context.Background(), key, nil)
if err != nil {
t.Fatalf("Object.GetRetention returned error: %v", err)
}
want := &ObjectGetRetentionResult{
XMLName: xml.Name{Local: "Retention"},
RetainUntilDate: "2023-05-18T07:19:55.000Z",
}
if !reflect.DeepEqual(res, want) {
t.Errorf("Object.GetRetention returned %+v, want %+v", res, want)
}
}
func TestBucketService_PutRetention(t *testing.T) {
setup()
defer teardown()
opt := &ObjectPutRetentionOptions{
RetainUntilDate: "2022-12-10T08:34:48.000Z",
Mode: "COMPLIANCE",
}
key := "example"
mux.HandleFunc("/example", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PUT")
vs := values{
"retention": "",
}
testFormValues(t, r, vs)
body := new(ObjectPutRetentionOptions)
xml.NewDecoder(r.Body).Decode(body)
want := opt
want.XMLName = xml.Name{Local: "Retention"}
if !reflect.DeepEqual(body, want) {
t.Errorf("Object.PutRetention request\n body: %+v\nwant %+v\n", body, want)
}
})
_, err := client.Object.PutRetention(context.Background(), key, opt)
if err != nil {
t.Fatalf("Object.GetRetention returned error: %v", err)
}
}