9 type OssOptionSuite struct{}
11 var _ = Suite(&OssOptionSuite{})
13 type optionTestCase struct {
19 var headerTestcases = []optionTestCase{
21 option: Meta("User", "baymax"),
22 key: "X-Oss-Meta-User",
26 option: ACL(ACLPrivate),
31 option: ContentType("plain/text"),
36 option: CacheControl("no-cache"),
41 option: ContentDisposition("Attachment; filename=example.txt"),
42 key: "Content-Disposition",
43 value: "Attachment; filename=example.txt",
46 option: ContentEncoding("gzip"),
47 key: "Content-Encoding",
51 option: Expires(pastDate),
53 value: pastDate.Format(http.TimeFormat),
61 option: Origin("localhost"),
66 option: CopySourceRange(0, 9),
67 key: "X-Oss-Copy-Source-Range",
71 option: IfModifiedSince(pastDate),
72 key: "If-Modified-Since",
73 value: pastDate.Format(http.TimeFormat),
76 option: IfUnmodifiedSince(futureDate),
77 key: "If-Unmodified-Since",
78 value: futureDate.Format(http.TimeFormat),
81 option: IfMatch("xyzzy"),
86 option: IfNoneMatch("xyzzy"),
91 option: CopySource("bucket_name", "object_name"),
92 key: "X-Oss-Copy-Source",
93 value: "/bucket_name/object_name",
96 option: CopySourceIfModifiedSince(pastDate),
97 key: "X-Oss-Copy-Source-If-Modified-Since",
98 value: pastDate.Format(http.TimeFormat),
101 option: CopySourceIfUnmodifiedSince(futureDate),
102 key: "X-Oss-Copy-Source-If-Unmodified-Since",
103 value: futureDate.Format(http.TimeFormat),
106 option: CopySourceIfMatch("xyzzy"),
107 key: "X-Oss-Copy-Source-If-Match",
111 option: CopySourceIfNoneMatch("xyzzy"),
112 key: "X-Oss-Copy-Source-If-None-Match",
116 option: MetadataDirective(MetaCopy),
117 key: "X-Oss-Metadata-Directive",
121 option: ServerSideEncryption("AES256"),
122 key: "X-Oss-Server-Side-Encryption",
126 option: ObjectACL(ACLPrivate),
127 key: "X-Oss-Object-Acl",
131 option: ObjectStorageClass(StorageStandard),
132 key: "X-Oss-Storage-Class",
136 option: Callback("JTdCJTIyY2FsbGJhY2tVcmwlMjIlM0ElMjJleGFtcGxlLmNvbS9pbmRleC5odG1sJTIyJTdE"),
137 key: "X-Oss-Callback",
138 value: "JTdCJTIyY2FsbGJhY2tVcmwlMjIlM0ElMjJleGFtcGxlLmNvbS9pbmRleC5odG1sJTIyJTdE",
141 option: CallbackVar("JTdCJTIyeCUzQXZhcjElMjIlM0ElMjJ2YWx1ZTElMjIlMkMlMjJ4JTNBdmFyMiUyMiUzQSUyMnZhbHVlMiUyMiU3RA=="),
142 key: "X-Oss-Callback-Var",
143 value: "JTdCJTIyeCUzQXZhcjElMjIlM0ElMjJ2YWx1ZTElMjIlMkMlMjJ4JTNBdmFyMiUyMiUzQSUyMnZhbHVlMiUyMiU3RA==",
146 option: ContentLanguage("zh-CN"),
147 key: "Content-Language",
151 option: ServerSideEncryptionKeyID("xossekid"),
152 key: "X-Oss-Server-Side-Encryption-Key-Id",
157 func (s *OssOptionSuite) TestHeaderOptions(c *C) {
158 for _, testcase := range headerTestcases {
159 headers := make(map[string]optionValue)
160 err := testcase.option(headers)
163 expected, actual := testcase.value, headers[testcase.key].Value
164 c.Assert(expected, Equals, actual)
168 var paramTestCases = []optionTestCase{
170 option: Delimiter("/"),
175 option: Marker("abc"),
180 option: MaxKeys(150),
185 option: Prefix("fun"),
190 option: EncodingType("ascii"),
191 key: "encoding-type",
195 option: MaxUploads(100),
200 option: KeyMarker("abc"),
205 option: UploadIDMarker("xyz"),
206 key: "upload-id-marker",
210 option: MaxParts(1000),
215 option: PartNumberMarker(1),
216 key: "part-number-marker",
220 option: Process("image/format,png"),
221 key: "x-oss-process",
222 value: "image/format,png",
226 func (s *OssOptionSuite) TestParamOptions(c *C) {
227 for _, testcase := range paramTestCases {
228 params := make(map[string]optionValue)
229 err := testcase.option(params)
232 expected, actual := testcase.value, params[testcase.key].Value
233 c.Assert(expected, Equals, actual)
237 func (s *OssOptionSuite) TestHandleOptions(c *C) {
238 headers := make(map[string]string)
239 options := []Option{}
241 for _, testcase := range headerTestcases {
242 options = append(options, testcase.option)
245 err := handleOptions(headers, options)
248 for _, testcase := range headerTestcases {
249 expected, actual := testcase.value, headers[testcase.key]
250 c.Assert(expected, Equals, actual)
253 options = []Option{IfMatch(""), nil}
254 headers = map[string]string{}
255 err = handleOptions(headers, options)
257 c.Assert(len(headers), Equals, 1)
260 func (s *OssOptionSuite) TestHandleParams(c *C) {
261 client, err := New(endpoint, accessID, accessKey)
264 options := []Option{}
266 for _, testcase := range paramTestCases {
267 options = append(options, testcase.option)
270 params, err := GetRawParams(options)
273 out := client.Conn.getURLParams(params)
274 c.Assert(len(out), Equals, 191)
276 options = []Option{KeyMarker(""), nil}
278 params, err = GetRawParams(options)
281 out = client.Conn.getURLParams(params)
282 c.Assert(out, Equals, "key-marker=")
285 func (s *OssOptionSuite) TestFindOption(c *C) {
286 options := []Option{}
288 for _, testcase := range headerTestcases {
289 options = append(options, testcase.option)
292 str, err := FindOption(options, "X-Oss-Acl", "")
294 c.Assert(str, Equals, "private")
296 str, err = FindOption(options, "MyProp", "")
298 c.Assert(str, Equals, "")
301 func (s *OssOptionSuite) TestDeleteOption(c *C) {
302 options := []Option{VersionId("123"), VersionIdMarker("456"), KeyMarker("789")}
303 str, err := FindOption(options, "versionId", "")
304 c.Assert(str, Equals, "123")
307 skipOption := DeleteOption(options, "versionId")
308 str, err = FindOption(skipOption, "versionId", "")
309 c.Assert(str, Equals, "")
311 str, err = FindOption(skipOption, "version-id-marker", "")
312 c.Assert(str, Equals, "456")
314 str, err = FindOption(skipOption, "key-marker", "")
315 c.Assert(str, Equals, "789")