type_test.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. package oss
  2. import (
  3. "net/url"
  4. "sort"
  5. . "gopkg.in/check.v1"
  6. )
  7. type OssTypeSuite struct{}
  8. var _ = Suite(&OssTypeSuite{})
  9. var (
  10. goStr = "go go + go <> go"
  11. chnStr = "试问闲情几许"
  12. goURLStr = url.QueryEscape(goStr)
  13. chnURLStr = url.QueryEscape(chnStr)
  14. )
  15. func (s *OssTypeSuite) TestConvLifecycleRule(c *C) {
  16. r1 := BuildLifecycleRuleByDate("id1", "one", true, 2015, 11, 11)
  17. r2 := BuildLifecycleRuleByDays("id2", "two", false, 3)
  18. rs := convLifecycleRule([]LifecycleRule{r1})
  19. c.Assert(rs[0].ID, Equals, "id1")
  20. c.Assert(rs[0].Prefix, Equals, "one")
  21. c.Assert(rs[0].Status, Equals, "Enabled")
  22. c.Assert(rs[0].Expiration.Date, Equals, "2015-11-11T00:00:00.000Z")
  23. c.Assert(rs[0].Expiration.Days, Equals, 0)
  24. rs = convLifecycleRule([]LifecycleRule{r2})
  25. c.Assert(rs[0].ID, Equals, "id2")
  26. c.Assert(rs[0].Prefix, Equals, "two")
  27. c.Assert(rs[0].Status, Equals, "Disabled")
  28. c.Assert(rs[0].Expiration.Date, Equals, "")
  29. c.Assert(rs[0].Expiration.Days, Equals, 3)
  30. }
  31. func (s *OssTypeSuite) TestDecodeDeleteObjectsResult(c *C) {
  32. var res DeleteObjectsResult
  33. err := decodeDeleteObjectsResult(&res)
  34. c.Assert(err, IsNil)
  35. res.DeletedObjects = []string{""}
  36. err = decodeDeleteObjectsResult(&res)
  37. c.Assert(err, IsNil)
  38. c.Assert(res.DeletedObjects[0], Equals, "")
  39. res.DeletedObjects = []string{goURLStr, chnURLStr}
  40. err = decodeDeleteObjectsResult(&res)
  41. c.Assert(err, IsNil)
  42. c.Assert(res.DeletedObjects[0], Equals, goStr)
  43. c.Assert(res.DeletedObjects[1], Equals, chnStr)
  44. }
  45. func (s *OssTypeSuite) TestDecodeListObjectsResult(c *C) {
  46. var res ListObjectsResult
  47. err := decodeListObjectsResult(&res)
  48. c.Assert(err, IsNil)
  49. res = ListObjectsResult{}
  50. err = decodeListObjectsResult(&res)
  51. c.Assert(err, IsNil)
  52. res = ListObjectsResult{Prefix: goURLStr, Marker: goURLStr,
  53. Delimiter: goURLStr, NextMarker: goURLStr,
  54. Objects: []ObjectProperties{{Key: chnURLStr}},
  55. CommonPrefixes: []string{chnURLStr}}
  56. err = decodeListObjectsResult(&res)
  57. c.Assert(err, IsNil)
  58. c.Assert(res.Prefix, Equals, goStr)
  59. c.Assert(res.Marker, Equals, goStr)
  60. c.Assert(res.Delimiter, Equals, goStr)
  61. c.Assert(res.NextMarker, Equals, goStr)
  62. c.Assert(res.Objects[0].Key, Equals, chnStr)
  63. c.Assert(res.CommonPrefixes[0], Equals, chnStr)
  64. }
  65. func (s *OssTypeSuite) TestDecodeListMultipartUploadResult(c *C) {
  66. res := ListMultipartUploadResult{}
  67. err := decodeListMultipartUploadResult(&res)
  68. c.Assert(err, IsNil)
  69. res = ListMultipartUploadResult{Prefix: goURLStr, KeyMarker: goURLStr,
  70. Delimiter: goURLStr, NextKeyMarker: goURLStr,
  71. Uploads: []UncompletedUpload{{Key: chnURLStr}}}
  72. err = decodeListMultipartUploadResult(&res)
  73. c.Assert(err, IsNil)
  74. c.Assert(res.Prefix, Equals, goStr)
  75. c.Assert(res.KeyMarker, Equals, goStr)
  76. c.Assert(res.Delimiter, Equals, goStr)
  77. c.Assert(res.NextKeyMarker, Equals, goStr)
  78. c.Assert(res.Uploads[0].Key, Equals, chnStr)
  79. }
  80. func (s *OssTypeSuite) TestSortUploadPart(c *C) {
  81. parts := []UploadPart{}
  82. sort.Sort(uploadParts(parts))
  83. c.Assert(len(parts), Equals, 0)
  84. parts = []UploadPart{
  85. {PartNumber: 5, ETag: "E5"},
  86. {PartNumber: 1, ETag: "E1"},
  87. {PartNumber: 4, ETag: "E4"},
  88. {PartNumber: 2, ETag: "E2"},
  89. {PartNumber: 3, ETag: "E3"},
  90. }
  91. sort.Sort(uploadParts(parts))
  92. c.Assert(parts[0].PartNumber, Equals, 1)
  93. c.Assert(parts[0].ETag, Equals, "E1")
  94. c.Assert(parts[1].PartNumber, Equals, 2)
  95. c.Assert(parts[1].ETag, Equals, "E2")
  96. c.Assert(parts[2].PartNumber, Equals, 3)
  97. c.Assert(parts[2].ETag, Equals, "E3")
  98. c.Assert(parts[3].PartNumber, Equals, 4)
  99. c.Assert(parts[3].ETag, Equals, "E4")
  100. c.Assert(parts[4].PartNumber, Equals, 5)
  101. c.Assert(parts[4].ETag, Equals, "E5")
  102. }