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.

203 lines
5.6 KiB

  1. package cos
  2. import (
  3. "context"
  4. "net/http"
  5. "testing"
  6. )
  7. func TestCIService_CreateDocProcessJobs(t *testing.T) {
  8. setup()
  9. defer teardown()
  10. wantBody := "<Request><Tag>DocProcess</Tag><Input><Object>1.doc</Object></Input>" +
  11. "<Operation><Output><Region>ap-chongqing</Region><Bucket>examplebucket-1250000000</Bucket>" +
  12. "<Object>big/test-${Number}</Object></Output><DocProcess>" +
  13. "<TgtType>png</TgtType><StartPage>1</StartPage><EndPage>-1</EndPage>" +
  14. "<ImageParams>watermark/1/image/aHR0cDovL3Rlc3QwMDUtMTI1MTcwNDcwOC5jb3MuYXAtY2hvbmdxaW5nLm15cWNsb3VkLmNvbS8xLmpwZw==/gravity/southeast</ImageParams>" +
  15. "</DocProcess></Operation><QueueId>p532fdead78444e649e1a4467c1cd19d3</QueueId></Request>"
  16. mux.HandleFunc("/doc_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. createJobOpt := &CreateDocProcessJobsOptions{
  22. Tag: "DocProcess",
  23. Input: &DocProcessJobInput{
  24. Object: "1.doc",
  25. },
  26. Operation: &DocProcessJobOperation{
  27. Output: &DocProcessJobOutput{
  28. Region: "ap-chongqing",
  29. Object: "big/test-${Number}",
  30. Bucket: "examplebucket-1250000000",
  31. },
  32. DocProcess: &DocProcessJobDocProcess{
  33. TgtType: "png",
  34. StartPage: 1,
  35. EndPage: -1,
  36. ImageParams: "watermark/1/image/aHR0cDovL3Rlc3QwMDUtMTI1MTcwNDcwOC5jb3MuYXAtY2hvbmdxaW5nLm15cWNsb3VkLmNvbS8xLmpwZw==/gravity/southeast",
  37. },
  38. },
  39. QueueId: "p532fdead78444e649e1a4467c1cd19d3",
  40. }
  41. _, _, err := client.CI.CreateDocProcessJobs(context.Background(), createJobOpt)
  42. if err != nil {
  43. t.Fatalf("CI.CreateDocProcessJobs returned error: %v", err)
  44. }
  45. }
  46. func TestCIService_DescribeDocProcessJob(t *testing.T) {
  47. setup()
  48. defer teardown()
  49. jobID := "d13cfd584cd9011ea820b597ad1785a2f"
  50. mux.HandleFunc("/doc_jobs"+"/"+jobID, func(w http.ResponseWriter, r *http.Request) {
  51. testMethod(t, r, http.MethodGet)
  52. })
  53. _, _, err := client.CI.DescribeDocProcessJob(context.Background(), jobID)
  54. if err != nil {
  55. t.Fatalf("CI.DescribeDocProcessJob returned error: %v", err)
  56. }
  57. }
  58. func TestCIService_DescribeDocProcessJobs(t *testing.T) {
  59. setup()
  60. defer teardown()
  61. mux.HandleFunc("/doc_jobs", func(w http.ResponseWriter, r *http.Request) {
  62. testMethod(t, r, http.MethodGet)
  63. v := values{
  64. "queueId": "QueueID",
  65. "tag": "DocProcess",
  66. }
  67. testFormValues(t, r, v)
  68. })
  69. opt := &DescribeDocProcessJobsOptions{
  70. QueueId: "QueueID",
  71. Tag: "DocProcess",
  72. }
  73. _, _, err := client.CI.DescribeDocProcessJobs(context.Background(), opt)
  74. if err != nil {
  75. t.Fatalf("CI.DescribeDocProcessJobs returned error: %v", err)
  76. }
  77. }
  78. func TestCIService_DescribeDocProcessQueues(t *testing.T) {
  79. setup()
  80. defer teardown()
  81. mux.HandleFunc("/docqueue", func(w http.ResponseWriter, r *http.Request) {
  82. testMethod(t, r, http.MethodGet)
  83. v := values{
  84. "pageNumber": "1",
  85. "pageSize": "2",
  86. "queueIds": "p111a8dd208104ce3b11c78398f658ca8,p4318f85d2aa14c43b1dba6f9b78be9b3,aacb2bb066e9c4478834d4196e76c49d3",
  87. }
  88. testFormValues(t, r, v)
  89. })
  90. opt := &DescribeDocProcessQueuesOptions{
  91. QueueIds: "p111a8dd208104ce3b11c78398f658ca8,p4318f85d2aa14c43b1dba6f9b78be9b3,aacb2bb066e9c4478834d4196e76c49d3",
  92. PageNumber: 1,
  93. PageSize: 2,
  94. }
  95. _, _, err := client.CI.DescribeDocProcessQueues(context.Background(), opt)
  96. if err != nil {
  97. t.Fatalf("CI.DescribeDocProcessQueues returned error: %v", err)
  98. }
  99. }
  100. func TestCIService_UpdateDocProcessQueue(t *testing.T) {
  101. setup()
  102. defer teardown()
  103. queueID := "p2505d57bdf4c4329804b58a6a5fb1572"
  104. wantBody := "<Request><Name>markjrzhang4</Name><QueueID>p2505d57bdf4c4329804b58a6a5fb1572</QueueID>" +
  105. "<State>Active</State>" +
  106. "<NotifyConfig><Url>http://google.com/</Url><State>On</State>" +
  107. "<Type>Url</Type><Event>TransCodingFinish</Event>" +
  108. "</NotifyConfig></Request>"
  109. mux.HandleFunc("/docqueue/"+queueID, func(w http.ResponseWriter, r *http.Request) {
  110. testMethod(t, r, http.MethodPut)
  111. testBody(t, r, wantBody)
  112. })
  113. opt := &UpdateDocProcessQueueOptions{
  114. Name: "markjrzhang4",
  115. QueueID: queueID,
  116. State: "Active",
  117. NotifyConfig: &DocProcessQueueNotifyConfig{
  118. Url: "http://google.com/",
  119. State: "On",
  120. Type: "Url",
  121. Event: "TransCodingFinish",
  122. },
  123. }
  124. _, _, err := client.CI.UpdateDocProcessQueue(context.Background(), opt)
  125. if err != nil {
  126. t.Fatalf("CI.DescribeDocProcessQueues returned error: %v", err)
  127. }
  128. }
  129. func TestCIService_DescribeDocProcessBuckets(t *testing.T) {
  130. setup()
  131. defer teardown()
  132. mux.HandleFunc("/docbucket", func(w http.ResponseWriter, r *http.Request) {
  133. testMethod(t, r, http.MethodGet)
  134. v := values{
  135. "pageNumber": "1",
  136. "pageSize": "2",
  137. "regions": "ap-shanghai",
  138. }
  139. testFormValues(t, r, v)
  140. })
  141. opt := &DescribeDocProcessBucketsOptions{
  142. Regions: "ap-shanghai",
  143. PageNumber: 1,
  144. PageSize: 2,
  145. }
  146. _, _, err := client.CI.DescribeDocProcessBuckets(context.Background(), opt)
  147. if err != nil {
  148. t.Fatalf("CI.DescribeDocProcessBuckets returned error: %v", err)
  149. }
  150. }
  151. func TestCIService_DocPreview(t *testing.T) {
  152. setup()
  153. defer teardown()
  154. name := "sample.pdf"
  155. mux.HandleFunc("/"+name, func(w http.ResponseWriter, r *http.Request) {
  156. testMethod(t, r, http.MethodGet)
  157. v := values{
  158. "ci-process": "doc-preview",
  159. "page": "1",
  160. "ImageParams": "imageMogr2/thumbnail/!50p|watermark/2/text/5pWw5o2u5LiH6LGh/fill/I0ZGRkZGRg==/fontsize/30/dx/20/dy/20",
  161. }
  162. testFormValues(t, r, v)
  163. })
  164. opt := &DocPreviewOptions{
  165. Page: 1,
  166. ImageParams: "imageMogr2/thumbnail/!50p|watermark/2/text/5pWw5o2u5LiH6LGh/fill/I0ZGRkZGRg==/fontsize/30/dx/20/dy/20",
  167. }
  168. _, err := client.CI.DocPreview(context.Background(), name, opt)
  169. if err != nil {
  170. t.Fatalf("CI.DocPreview returned error: %v", err)
  171. }
  172. }