123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391 |
- package oss
- import (
- "net/url"
- "sort"
- . "gopkg.in/check.v1"
- )
- type OssTypeSuite struct{}
- var _ = Suite(&OssTypeSuite{})
- var (
- goStr = "go go + go <> go"
- chnStr = "试问闲情几许"
- goURLStr = url.QueryEscape(goStr)
- chnURLStr = url.QueryEscape(chnStr)
- )
- func (s *OssTypeSuite) TestDecodeDeleteObjectsResult(c *C) {
- var res DeleteObjectVersionsResult
- err := decodeDeleteObjectsResult(&res)
- c.Assert(err, IsNil)
- res.DeletedObjectsDetail = []DeletedKeyInfo{DeletedKeyInfo{Key: ""}}
- err = decodeDeleteObjectsResult(&res)
- c.Assert(err, IsNil)
- c.Assert(res.DeletedObjectsDetail[0].Key, Equals, "")
- res.DeletedObjectsDetail = []DeletedKeyInfo{DeletedKeyInfo{Key: goURLStr}, DeletedKeyInfo{Key: chnURLStr}}
- err = decodeDeleteObjectsResult(&res)
- c.Assert(err, IsNil)
- c.Assert(res.DeletedObjectsDetail[0].Key, Equals, goStr)
- c.Assert(res.DeletedObjectsDetail[1].Key, Equals, chnStr)
- }
- func (s *OssTypeSuite) TestDecodeListObjectsResult(c *C) {
- var res ListObjectsResult
- err := decodeListObjectsResult(&res)
- c.Assert(err, IsNil)
- res = ListObjectsResult{}
- err = decodeListObjectsResult(&res)
- c.Assert(err, IsNil)
- res = ListObjectsResult{Prefix: goURLStr, Marker: goURLStr,
- Delimiter: goURLStr, NextMarker: goURLStr,
- Objects: []ObjectProperties{{Key: chnURLStr}},
- CommonPrefixes: []string{chnURLStr}}
- err = decodeListObjectsResult(&res)
- c.Assert(err, IsNil)
- c.Assert(res.Prefix, Equals, goStr)
- c.Assert(res.Marker, Equals, goStr)
- c.Assert(res.Delimiter, Equals, goStr)
- c.Assert(res.NextMarker, Equals, goStr)
- c.Assert(res.Objects[0].Key, Equals, chnStr)
- c.Assert(res.CommonPrefixes[0], Equals, chnStr)
- }
- func (s *OssTypeSuite) TestDecodeListMultipartUploadResult(c *C) {
- res := ListMultipartUploadResult{}
- err := decodeListMultipartUploadResult(&res)
- c.Assert(err, IsNil)
- res = ListMultipartUploadResult{Prefix: goURLStr, KeyMarker: goURLStr,
- Delimiter: goURLStr, NextKeyMarker: goURLStr,
- Uploads: []UncompletedUpload{{Key: chnURLStr}}}
- err = decodeListMultipartUploadResult(&res)
- c.Assert(err, IsNil)
- c.Assert(res.Prefix, Equals, goStr)
- c.Assert(res.KeyMarker, Equals, goStr)
- c.Assert(res.Delimiter, Equals, goStr)
- c.Assert(res.NextKeyMarker, Equals, goStr)
- c.Assert(res.Uploads[0].Key, Equals, chnStr)
- }
- func (s *OssTypeSuite) TestSortUploadPart(c *C) {
- parts := []UploadPart{}
- sort.Sort(UploadParts(parts))
- c.Assert(len(parts), Equals, 0)
- parts = []UploadPart{
- {PartNumber: 5, ETag: "E5"},
- {PartNumber: 1, ETag: "E1"},
- {PartNumber: 4, ETag: "E4"},
- {PartNumber: 2, ETag: "E2"},
- {PartNumber: 3, ETag: "E3"},
- }
- sort.Sort(UploadParts(parts))
- c.Assert(parts[0].PartNumber, Equals, 1)
- c.Assert(parts[0].ETag, Equals, "E1")
- c.Assert(parts[1].PartNumber, Equals, 2)
- c.Assert(parts[1].ETag, Equals, "E2")
- c.Assert(parts[2].PartNumber, Equals, 3)
- c.Assert(parts[2].ETag, Equals, "E3")
- c.Assert(parts[3].PartNumber, Equals, 4)
- c.Assert(parts[3].ETag, Equals, "E4")
- c.Assert(parts[4].PartNumber, Equals, 5)
- c.Assert(parts[4].ETag, Equals, "E5")
- }
- func (s *OssTypeSuite) TestValidateLifecleRules(c *C) {
- expiration := LifecycleExpiration{
- Days: 30,
- CreatedBeforeDate: "2015-11-11T00:00:00.000Z",
- }
- rule := LifecycleRule{
- ID: "ruleID",
- Prefix: "prefix",
- Status: "Enabled",
- Expiration: &expiration,
- }
- rules := []LifecycleRule{rule}
- err := verifyLifecycleRules(rules)
- c.Assert(err, IsNil)
- expiration = LifecycleExpiration{
- Date: "2015-11-11T00:00:00.000Z",
- CreatedBeforeDate: "2015-11-11T00:00:00.000Z",
- }
- rule = LifecycleRule{
- ID: "ruleID",
- Prefix: "prefix",
- Status: "Enabled",
- Expiration: &expiration,
- }
- rules = []LifecycleRule{rule}
- err = verifyLifecycleRules(rules)
- c.Assert(err, IsNil)
- expiration = LifecycleExpiration{
- Days: 0,
- CreatedBeforeDate: "",
- Date: "",
- }
- rule = LifecycleRule{
- ID: "ruleID",
- Prefix: "prefix",
- Status: "Enabled",
- Expiration: &expiration,
- }
- rules = []LifecycleRule{rule}
- err = verifyLifecycleRules(rules)
- c.Assert(err, IsNil)
- abortMPU := LifecycleAbortMultipartUpload{
- Days: 30,
- CreatedBeforeDate: "2015-11-11T00:00:00.000Z",
- }
- rule = LifecycleRule{
- ID: "ruleID",
- Prefix: "prefix",
- Status: "Enabled",
- AbortMultipartUpload: &abortMPU,
- }
- rules = []LifecycleRule{rule}
- err = verifyLifecycleRules(rules)
- c.Assert(err, NotNil)
- abortMPU = LifecycleAbortMultipartUpload{
- Days: 0,
- CreatedBeforeDate: "",
- }
- rule = LifecycleRule{
- ID: "ruleID",
- Prefix: "prefix",
- Status: "Enabled",
- AbortMultipartUpload: &abortMPU,
- }
- rules = []LifecycleRule{rule}
- err = verifyLifecycleRules(rules)
- c.Assert(err, NotNil)
- transition := LifecycleTransition{
- Days: 30,
- CreatedBeforeDate: "2015-11-11T00:00:00.000Z",
- StorageClass: StorageIA,
- }
- rule = LifecycleRule{
- ID: "ruleID",
- Prefix: "prefix",
- Status: "Enabled",
- Transitions: []LifecycleTransition{transition},
- }
- rules = []LifecycleRule{rule}
- err = verifyLifecycleRules(rules)
- c.Assert(err, NotNil)
- transition = LifecycleTransition{
- Days: 0,
- CreatedBeforeDate: "",
- StorageClass: StorageIA,
- }
- rule = LifecycleRule{
- ID: "ruleID",
- Prefix: "prefix",
- Status: "Enabled",
- Transitions: []LifecycleTransition{transition},
- }
- rules = []LifecycleRule{rule}
- err = verifyLifecycleRules(rules)
- c.Assert(err, NotNil)
- transition = LifecycleTransition{
- Days: 30,
- StorageClass: StorageStandard,
- }
- rule = LifecycleRule{
- ID: "ruleID",
- Prefix: "prefix",
- Status: "Enabled",
- Transitions: []LifecycleTransition{transition},
- }
- rules = []LifecycleRule{rule}
- err = verifyLifecycleRules(rules)
- c.Assert(err, NotNil)
- transition = LifecycleTransition{
- CreatedBeforeDate: "2015-11-11T00:00:00.000Z",
- StorageClass: StorageStandard,
- }
- rule = LifecycleRule{
- ID: "ruleID",
- Prefix: "prefix",
- Status: "Enabled",
- Transitions: []LifecycleTransition{transition},
- }
- rules = []LifecycleRule{rule}
- err = verifyLifecycleRules(rules)
- c.Assert(err, IsNil)
- transition1 := LifecycleTransition{
- Days: 30,
- StorageClass: StorageIA,
- }
- transition2 := LifecycleTransition{
- Days: 60,
- StorageClass: StorageArchive,
- }
- transition3 := LifecycleTransition{
- Days: 100,
- StorageClass: StorageArchive,
- }
- rule = LifecycleRule{
- ID: "ruleID",
- Prefix: "prefix",
- Status: "Enabled",
- Transitions: []LifecycleTransition{transition1, transition2, transition3},
- }
- rules = []LifecycleRule{rule}
- err = verifyLifecycleRules(rules)
- c.Assert(err, IsNil)
- rule = LifecycleRule{
- ID: "ruleID",
- Prefix: "prefix",
- Status: "Enabled",
- }
- rules = []LifecycleRule{rule}
- err = verifyLifecycleRules(rules)
- c.Assert(err, IsNil)
- rules = []LifecycleRule{}
- err1 := verifyLifecycleRules(rules)
- c.Assert(err1, NotNil)
- expiration = LifecycleExpiration{
- Days: 30,
- }
- rule = LifecycleRule{
- ID: "ruleID",
- Prefix: "prefix",
- Status: "Enabled",
- Expiration: &expiration,
- }
- rules = []LifecycleRule{rule}
- err = verifyLifecycleRules(rules)
- c.Assert(err, IsNil)
- expiration = LifecycleExpiration{
- CreatedBeforeDate: "2015-11-11T00:00:00.000Z",
- }
- rule = LifecycleRule{
- ID: "ruleID",
- Prefix: "prefix",
- Status: "Enabled",
- Expiration: &expiration,
- }
- rules = []LifecycleRule{rule}
- err = verifyLifecycleRules(rules)
- c.Assert(err, IsNil)
- abortMPU = LifecycleAbortMultipartUpload{
- Days: 30,
- }
- rule = LifecycleRule{
- ID: "ruleID",
- Prefix: "prefix",
- Status: "Enabled",
- AbortMultipartUpload: &abortMPU,
- }
- rules = []LifecycleRule{rule}
- err = verifyLifecycleRules(rules)
- c.Assert(err, IsNil)
- abortMPU = LifecycleAbortMultipartUpload{
- CreatedBeforeDate: "2015-11-11T00:00:00.000Z",
- }
- rule = LifecycleRule{
- ID: "ruleID",
- Prefix: "prefix",
- Status: "Enabled",
- AbortMultipartUpload: &abortMPU,
- }
- rules = []LifecycleRule{rule}
- err = verifyLifecycleRules(rules)
- c.Assert(err, IsNil)
- expiration = LifecycleExpiration{
- Days: 30,
- }
- abortMPU = LifecycleAbortMultipartUpload{
- Days: 30,
- }
- rule = LifecycleRule{
- ID: "ruleID",
- Prefix: "prefix",
- Status: "Enabled",
- Expiration: &expiration,
- AbortMultipartUpload: &abortMPU,
- }
- rules = []LifecycleRule{rule}
- err = verifyLifecycleRules(rules)
- c.Assert(err, IsNil)
- expiration = LifecycleExpiration{
- CreatedBeforeDate: "2015-11-11T00:00:00.000Z",
- }
- abortMPU = LifecycleAbortMultipartUpload{
- Days: 30,
- }
- transition = LifecycleTransition{
- Days: 30,
- StorageClass: StorageIA,
- }
- rule = LifecycleRule{
- ID: "ruleID",
- Prefix: "prefix",
- Status: "Enabled",
- Expiration: &expiration,
- AbortMultipartUpload: &abortMPU,
- Transitions: []LifecycleTransition{transition},
- }
- rules = []LifecycleRule{rule}
- err = verifyLifecycleRules(rules)
- c.Assert(err, IsNil)
- expiration = LifecycleExpiration{
- CreatedBeforeDate: "2015-11-11T00:00:00.000Z",
- }
- abortMPU = LifecycleAbortMultipartUpload{
- Days: 30,
- }
- transition1 = LifecycleTransition{
- Days: 30,
- StorageClass: StorageIA,
- }
- transition2 = LifecycleTransition{
- Days: 60,
- StorageClass: StorageArchive,
- }
- rule = LifecycleRule{
- ID: "ruleID",
- Prefix: "prefix",
- Status: "Enabled",
- Expiration: &expiration,
- AbortMultipartUpload: &abortMPU,
- Transitions: []LifecycleTransition{transition1, transition2},
- }
- rules = []LifecycleRule{rule}
- err = verifyLifecycleRules(rules)
- c.Assert(err, IsNil)
- }
|