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.

170 lines
4.3 KiB

  1. package cos
  2. import (
  3. "context"
  4. "net/http"
  5. "testing"
  6. )
  7. func TestCIService_CreateMediaJobs(t *testing.T) {
  8. setup()
  9. defer teardown()
  10. wantBody := "<Request><Tag>Animation</Tag><Input><Object>test.mp4</Object></Input>" +
  11. "<Operation><Output><Region>ap-beijing</Region><Bucket>abc-1250000000</Bucket>" +
  12. "<Object>test-trans.gif</Object></Output>" +
  13. "<TemplateId>t1460606b9752148c4ab182f55163ba7cd</TemplateId>" +
  14. "</Operation><QueueId>p893bcda225bf4945a378da6662e81a89</QueueId>" +
  15. "<CallBack>https://www.callback.com</CallBack></Request>"
  16. mux.HandleFunc("/jobs", func(w http.ResponseWriter, r *http.Request) {
  17. testMethod(t, r, http.MethodPost)
  18. testHeader(t, r, "Content-Type", "application/xml")
  19. testBody(t, r, wantBody)
  20. })
  21. opt := &CreateMediaJobsOptions{
  22. Tag: "Animation",
  23. Input: &JobInput{
  24. Object: "test.mp4",
  25. },
  26. Operation: &MediaProcessJobOperation{
  27. Output: &JobOutput{
  28. Region: "ap-beijing",
  29. Bucket: "abc-1250000000",
  30. Object: "test-trans.gif",
  31. },
  32. TemplateId: "t1460606b9752148c4ab182f55163ba7cd",
  33. },
  34. QueueId: "p893bcda225bf4945a378da6662e81a89",
  35. CallBack: "https://www.callback.com",
  36. }
  37. _, _, err := client.CI.CreateMediaJobs(context.Background(), opt)
  38. if err != nil {
  39. t.Fatalf("CI.CreateMediaJobs returned errors: %v", err)
  40. }
  41. }
  42. func TestCIService_DescribeMediaJob(t *testing.T) {
  43. setup()
  44. defer teardown()
  45. jobID := "jabcsdssfeipplsdfwe"
  46. mux.HandleFunc("/jobs/"+jobID, func(w http.ResponseWriter, r *http.Request) {
  47. testMethod(t, r, http.MethodGet)
  48. })
  49. _, _, err := client.CI.DescribeMediaJob(context.Background(), jobID)
  50. if err != nil {
  51. t.Fatalf("CI.DescribeMediaJob returned error: %v", err)
  52. }
  53. }
  54. func TestCIService_DescribeMediaJobs(t *testing.T) {
  55. setup()
  56. defer teardown()
  57. queueId := "aaaaaaaaaaa"
  58. tag := "Animation"
  59. mux.HandleFunc("/jobs", func(w http.ResponseWriter, r *http.Request) {
  60. testMethod(t, r, http.MethodGet)
  61. v := values{
  62. "queueId": queueId,
  63. "tag": tag,
  64. }
  65. testFormValues(t, r, v)
  66. })
  67. opt := &DescribeMediaJobsOptions{
  68. QueueId: queueId,
  69. Tag: tag,
  70. }
  71. _, _, err := client.CI.DescribeMediaJobs(context.Background(), opt)
  72. if err != nil {
  73. t.Fatalf("CI.DescribeMediaJobs returned error: %v", err)
  74. }
  75. }
  76. func TestCIService_DescribeMediaProcessQueues(t *testing.T) {
  77. setup()
  78. defer teardown()
  79. queueIds := "A,B,C"
  80. mux.HandleFunc("/queue", func(w http.ResponseWriter, r *http.Request) {
  81. testMethod(t, r, http.MethodGet)
  82. v := values{
  83. "queueIds": queueIds,
  84. }
  85. testFormValues(t, r, v)
  86. })
  87. opt := &DescribeMediaProcessQueuesOptions{
  88. QueueIds: queueIds,
  89. }
  90. _, _, err := client.CI.DescribeMediaProcessQueues(context.Background(), opt)
  91. if err != nil {
  92. t.Fatalf("CI.DescribeMediaProcessQueues returned error: %v", err)
  93. }
  94. }
  95. func TestCIService_UpdateMediaProcessQueue(t *testing.T) {
  96. setup()
  97. defer teardown()
  98. queueID := "p8eb46b8cc1a94bc09512d16c5c4f4d3a"
  99. wantBody := "<Request><Name>QueueName</Name><QueueID>" + queueID + "</QueueID><State>Active</State>" +
  100. "<NotifyConfig><Url>test.com</Url><State>On</State><Type>Url</Type><Event>TransCodingFinish</Event>" +
  101. "</NotifyConfig></Request>"
  102. mux.HandleFunc("/queue/"+queueID, func(w http.ResponseWriter, r *http.Request) {
  103. testMethod(t, r, http.MethodPut)
  104. testHeader(t, r, "Content-Type", "application/xml")
  105. testBody(t, r, wantBody)
  106. })
  107. opt := &UpdateMediaProcessQueueOptions{
  108. Name: "QueueName",
  109. QueueID: queueID,
  110. State: "Active",
  111. NotifyConfig: &MediaProcessQueueNotifyConfig{
  112. Url: "test.com",
  113. State: "On",
  114. Type: "Url",
  115. Event: "TransCodingFinish",
  116. },
  117. }
  118. _, _, err := client.CI.UpdateMediaProcessQueue(context.Background(), opt)
  119. if err != nil {
  120. t.Fatalf("CI.UpdateMediaProcessQueue returned error: %v", err)
  121. }
  122. }
  123. func TestCIService_DescribeMediaProcessBuckets(t *testing.T) {
  124. setup()
  125. defer teardown()
  126. regions := "ap-shanghai,ap-gaungzhou"
  127. bucketName := "testbucket-1250000000"
  128. mux.HandleFunc("/mediabucket", func(w http.ResponseWriter, r *http.Request) {
  129. testMethod(t, r, http.MethodGet)
  130. v := values{
  131. "regions": regions,
  132. "bucketName": bucketName,
  133. }
  134. testFormValues(t, r, v)
  135. })
  136. opt := &DescribeMediaProcessBucketsOptions{
  137. Regions: regions,
  138. BucketName: bucketName,
  139. }
  140. _, _, err := client.CI.DescribeMediaProcessBuckets(context.Background(), opt)
  141. if err != nil {
  142. t.Fatalf("CI.DescribeMediaProcessBuckets returned error: %v", err)
  143. }
  144. }