From d1c9ff5808b601b7a918b152c8fba7ac2d5976c4 Mon Sep 17 00:00:00 2001 From: Chloroplast Yu Date: Thu, 10 Jun 2021 20:13:49 +0800 Subject: [PATCH 1/2] Complete unit tests in ci_media.go and fix several issues in ci_media.go. --- .gitignore | 4 +- ci_media.go | 11 ++-- ci_media_test.go | 170 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 179 insertions(+), 6 deletions(-) create mode 100644 ci_media_test.go diff --git a/.gitignore b/.gitignore index 7da6873..8d1693a 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,8 @@ # Folders _obj _test +.idea +.DS_Store # Architecture specific extensions/prefixes *.[568vq] @@ -26,4 +28,4 @@ dist/ cover.html cover.out covprofile -coverage.html \ No newline at end of file +coverage.html diff --git a/ci_media.go b/ci_media.go index 9a10c61..971ba7b 100644 --- a/ci_media.go +++ b/ci_media.go @@ -112,6 +112,7 @@ type CreateMediaJobsOptions struct { Input *JobInput `xml:"Input,omitempty"` Operation *MediaProcessJobOperation `xml:"Operation,omitempty"` QueueId string `xml:"QueueId,omitempty"` + CallBack string `xml:"CallBack,omitempty"` } type MediaProcessJobDetail struct { @@ -150,7 +151,7 @@ type DescribeMediaProcessJobResult struct { NonExistJobIds string `xml:"NonExistJobIds,omitempty"` } -func (s *CIService) DescribeMediaJobs(ctx context.Context, jobid string) (*DescribeMediaProcessJobResult, *Response, error) { +func (s *CIService) DescribeMediaJob(ctx context.Context, jobid string) (*DescribeMediaProcessJobResult, *Response, error) { var res DescribeMediaProcessJobResult sendOpt := sendOptions{ baseURL: s.client.BaseURL.CIURL, @@ -162,7 +163,7 @@ func (s *CIService) DescribeMediaJobs(ctx context.Context, jobid string) (*Descr return &res, resp, err } -type DescribeMediaProcessJobsOptions struct { +type DescribeMediaJobsOptions struct { QueueId string `url:"queueId,omitempty"` Tag string `url:"tag,omitempty"` OrderByTime string `url:"orderByTime,omitempty"` @@ -173,14 +174,14 @@ type DescribeMediaProcessJobsOptions struct { EndCreationTime string `url:"endCreationTime,omitempty"` } -type DescribeMediaProcessJobsResult struct { +type DescribeMediaJobsResult struct { XMLName xml.Name `xml:"Response"` JobsDetail []DocProcessJobDetail `xml:"JobsDetail,omitempty"` NextToken string `xml:"NextToken,omitempty"` } -func (s *CIService) DescribeMediaProcessJobs(ctx context.Context, opt *DescribeMediaProcessJobsOptions) (*DescribeMediaProcessJobsResult, *Response, error) { - var res DescribeMediaProcessJobsResult +func (s *CIService) DescribeMediaJobs(ctx context.Context, opt *DescribeMediaJobsOptions) (*DescribeMediaJobsResult, *Response, error) { + var res DescribeMediaJobsResult sendOpt := sendOptions{ baseURL: s.client.BaseURL.CIURL, uri: "/jobs", diff --git a/ci_media_test.go b/ci_media_test.go new file mode 100644 index 0000000..26b1167 --- /dev/null +++ b/ci_media_test.go @@ -0,0 +1,170 @@ +package cos + +import ( + "context" + "net/http" + "testing" +) + +func TestCIService_CreateMediaJobs(t *testing.T) { + setup() + defer teardown() + + wantBody := "Animationtest.mp4" + + "ap-beijingabc-1250000000" + + "test-trans.gif" + + "t1460606b9752148c4ab182f55163ba7cd" + + "p893bcda225bf4945a378da6662e81a89" + + "https://www.callback.com" + + mux.HandleFunc("/jobs", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, http.MethodPost) + testHeader(t, r, "Content-Type", "application/xml") + testBody(t, r, wantBody) + }) + + opt := &CreateMediaJobsOptions{ + Tag: "Animation", + Input: &JobInput{ + Object: "test.mp4", + }, + Operation: &MediaProcessJobOperation{ + Output: &JobOutput{ + Region: "ap-beijing", + Bucket: "abc-1250000000", + Object: "test-trans.gif", + }, + TemplateId: "t1460606b9752148c4ab182f55163ba7cd", + }, + QueueId: "p893bcda225bf4945a378da6662e81a89", + CallBack: "https://www.callback.com", + } + + _, _, err := client.CI.CreateMediaJobs(context.Background(), opt) + if err != nil { + t.Fatalf("CI.CreateMediaJobs returned errors: %v", err) + } +} + +func TestCIService_DescribeMediaJob(t *testing.T) { + setup() + defer teardown() + + jobID := "jabcsdssfeipplsdfwe" + mux.HandleFunc("/jobs/"+jobID, func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, http.MethodGet) + }) + + _, _, err := client.CI.DescribeMediaJob(context.Background(), jobID) + if err != nil { + t.Fatalf("CI.DescribeMediaJob returned error: %v", err) + } +} + +func TestCIService_DescribeMediaJobs(t *testing.T) { + setup() + defer teardown() + + queueId := "aaaaaaaaaaa" + tag := "Animation" + + mux.HandleFunc("/jobs", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, http.MethodGet) + v := values{ + "queueId": queueId, + "tag": tag, + } + testFormValues(t, r, v) + }) + + opt := &DescribeMediaJobsOptions{ + QueueId: queueId, + Tag: tag, + } + + _, _, err := client.CI.DescribeMediaJobs(context.Background(), opt) + if err != nil { + t.Fatalf("CI.DescribeMediaJobs returned error: %v", err) + } +} + +func TestCIService_DescribeMediaProcessQueues(t *testing.T) { + setup() + defer teardown() + + queueIds := "A,B,C" + mux.HandleFunc("/queue", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, http.MethodGet) + v := values{ + "queueIds": queueIds, + } + testFormValues(t, r, v) + }) + + opt := &DescribeMediaProcessQueuesOptions{ + QueueIds: queueIds, + } + + _, _, err := client.CI.DescribeMediaProcessQueues(context.Background(), opt) + if err != nil { + t.Fatalf("CI.DescribeMediaProcessQueues returned error: %v", err) + } +} + +func TestCIService_UpdateMediaProcessQueue(t *testing.T) { + setup() + defer teardown() + + queueID := "p8eb46b8cc1a94bc09512d16c5c4f4d3a" + wantBody := "QueueName" + queueID + "Active" + + "test.comOnUrlTransCodingFinish" + + "" + mux.HandleFunc("/queue/"+queueID, func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, http.MethodPut) + testHeader(t, r, "Content-Type", "application/xml") + testBody(t, r, wantBody) + }) + + opt := &UpdateMediaProcessQueueOptions{ + Name: "QueueName", + QueueID: queueID, + State: "Active", + NotifyConfig: &MediaProcessQueueNotifyConfig{ + Url: "test.com", + State: "On", + Type: "Url", + Event: "TransCodingFinish", + }, + } + + _, _, err := client.CI.UpdateMediaProcessQueue(context.Background(), opt) + if err != nil { + t.Fatalf("CI.UpdateMediaProcessQueue returned error: %v", err) + } +} + +func TestCIService_DescribeMediaProcessBuckets(t *testing.T) { + setup() + defer teardown() + + regions := "ap-shanghai,ap-gaungzhou" + bucketName := "testbucket-1250000000" + mux.HandleFunc("/mediabucket", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, http.MethodGet) + v := values{ + "regions": regions, + "bucketName": bucketName, + } + testFormValues(t, r, v) + }) + + opt := &DescribeMediaProcessBucketsOptions{ + Regions: regions, + BucketName: bucketName, + } + + _, _, err := client.CI.DescribeMediaProcessBuckets(context.Background(), opt) + if err != nil { + t.Fatalf("CI.DescribeMediaProcessBuckets returned error: %v", err) + } +} From ef23bab44479fc5a1960b9357b64e556402527d8 Mon Sep 17 00:00:00 2001 From: Chloroplast Yu Date: Thu, 10 Jun 2021 20:25:10 +0800 Subject: [PATCH 2/2] Fix ci_media.go and example/CI/media_process/media_process.go --- ci_media.go | 2 +- example/CI/media_process/media_process.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ci_media.go b/ci_media.go index 971ba7b..b9dfd90 100644 --- a/ci_media.go +++ b/ci_media.go @@ -112,7 +112,7 @@ type CreateMediaJobsOptions struct { Input *JobInput `xml:"Input,omitempty"` Operation *MediaProcessJobOperation `xml:"Operation,omitempty"` QueueId string `xml:"QueueId,omitempty"` - CallBack string `xml:"CallBack,omitempty"` + CallBack string `xml:"CallBack,omitempty"` } type MediaProcessJobDetail struct { diff --git a/example/CI/media_process/media_process.go b/example/CI/media_process/media_process.go index 15466b8..c822a02 100644 --- a/example/CI/media_process/media_process.go +++ b/example/CI/media_process/media_process.go @@ -91,7 +91,7 @@ func main() { fmt.Printf("%+v\n", createJobRes.JobsDetail) // DescribeMediaJobs - DescribeJobRes, _, err := c.CI.DescribeMediaJobs(context.Background(), createJobRes.JobsDetail.JobId) + DescribeJobRes, _, err := c.CI.DescribeMediaJob(context.Background(), createJobRes.JobsDetail.JobId) log_status(err) fmt.Printf("%+v\n", DescribeJobRes.JobsDetail) }