You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

121 lines
3.1 KiB

  1. package cos
  2. import (
  3. "context"
  4. "encoding/xml"
  5. "fmt"
  6. "net/http"
  7. "reflect"
  8. "testing"
  9. )
  10. func TestBucketService_ListMultipartUploads(t *testing.T) {
  11. setup()
  12. defer teardown()
  13. mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
  14. testMethod(t, r, "GET")
  15. vs := values{
  16. "uploads": "",
  17. "prefix": "t",
  18. }
  19. testFormValues(t, r, vs)
  20. fmt.Fprint(w, `<ListMultipartUploadsResult>
  21. <Bucket>test-1253846586</Bucket>
  22. <Encoding-Type/>
  23. <KeyMarker/>
  24. <UploadIdMarker/>
  25. <MaxUploads>1000</MaxUploads>
  26. <Prefix>t</Prefix>
  27. <Delimiter>/</Delimiter>
  28. <IsTruncated>false</IsTruncated>
  29. <CommonPrefixs>
  30. <Prefix>test/</Prefix>
  31. </CommonPrefixs>
  32. <Upload>
  33. <Key>test_multipart.txt</Key>
  34. <UploadId>14972623850a5de3f4f10605ab9f339c8bdf1b77e06f03fb981e7e76c86554b7bdb6072b36</UploadId>
  35. <Initiator>
  36. <ID>100000760461/100000760461</ID>
  37. <DisplayName/>
  38. </Initiator>
  39. <Owner>
  40. <ID>100000760461/100000760461</ID>
  41. <DisplayName/>
  42. </Owner>
  43. <StorageClass>STANDARD</StorageClass>
  44. <Initiated>2017-06-12T10:13:05.000Z</Initiated>
  45. </Upload>
  46. <Upload>
  47. <Key>test_multipar2t.txt</Key>
  48. <UploadId>1497515958744e899fc341bfbb995ebd57b395f63930411d855aaac1b5cd7d834a15442831</UploadId>
  49. <Initiator>
  50. <ID>qcs::cam::uin/100000760461:uin/100000760461</ID>
  51. <DisplayName>100000760461</DisplayName>
  52. </Initiator>
  53. <Owner>
  54. <ID>qcs::cam::uin/100000760461:uin/100000760461</ID>
  55. <DisplayName>100000760461</DisplayName>
  56. </Owner>
  57. <StorageClass>STANDARD</StorageClass>
  58. <Initiated>2017-06-15T08:39:18.000Z</Initiated>
  59. </Upload>
  60. </ListMultipartUploadsResult>`)
  61. })
  62. opt := &ListMultipartUploadsOptions{
  63. Prefix: "t",
  64. }
  65. ref, _, err := client.Bucket.ListMultipartUploads(context.Background(), opt)
  66. if err != nil {
  67. t.Fatalf("Bucket.ListMultipartUploads returned error: %v", err)
  68. }
  69. want := &ListMultipartUploadsResult{
  70. XMLName: xml.Name{Local: "ListMultipartUploadsResult"},
  71. Bucket: "test-1253846586",
  72. MaxUploads: 1000,
  73. IsTruncated: false,
  74. Uploads: []struct {
  75. Key string
  76. UploadID string `xml:"UploadId"`
  77. StorageClass string
  78. Initiator *Initiator
  79. Owner *Owner
  80. Initiated string
  81. }{
  82. {
  83. Key: "test_multipart.txt",
  84. UploadID: "14972623850a5de3f4f10605ab9f339c8bdf1b77e06f03fb981e7e76c86554b7bdb6072b36",
  85. Initiator: &Initiator{
  86. ID: "100000760461/100000760461",
  87. },
  88. Owner: &Owner{
  89. ID: "100000760461/100000760461",
  90. },
  91. StorageClass: "STANDARD",
  92. Initiated: "2017-06-12T10:13:05.000Z",
  93. },
  94. {
  95. Key: "test_multipar2t.txt",
  96. UploadID: "1497515958744e899fc341bfbb995ebd57b395f63930411d855aaac1b5cd7d834a15442831",
  97. Initiator: &Initiator{
  98. ID: "qcs::cam::uin/100000760461:uin/100000760461",
  99. DisplayName: "100000760461",
  100. },
  101. Owner: &Owner{
  102. ID: "qcs::cam::uin/100000760461:uin/100000760461",
  103. DisplayName: "100000760461",
  104. },
  105. StorageClass: "STANDARD",
  106. Initiated: "2017-06-15T08:39:18.000Z",
  107. },
  108. },
  109. Prefix: "t",
  110. CommonPrefixes: []string{"test/"},
  111. }
  112. if !reflect.DeepEqual(ref, want) {
  113. t.Errorf("Bucket.ListMultipartUploads returned \n%+v, want \n%+v", ref, want)
  114. }
  115. }