Complete unit tests in ci_media.go and fix several issues in ci_media.go.
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -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
|
||||
coverage.html
|
||||
|
||||
11
ci_media.go
11
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",
|
||||
|
||||
170
ci_media_test.go
Normal file
170
ci_media_test.go
Normal file
@@ -0,0 +1,170 @@
|
||||
package cos
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestCIService_CreateMediaJobs(t *testing.T) {
|
||||
setup()
|
||||
defer teardown()
|
||||
|
||||
wantBody := "<Request><Tag>Animation</Tag><Input><Object>test.mp4</Object></Input>" +
|
||||
"<Operation><Output><Region>ap-beijing</Region><Bucket>abc-1250000000</Bucket>" +
|
||||
"<Object>test-trans.gif</Object></Output>" +
|
||||
"<TemplateId>t1460606b9752148c4ab182f55163ba7cd</TemplateId>" +
|
||||
"</Operation><QueueId>p893bcda225bf4945a378da6662e81a89</QueueId>" +
|
||||
"<CallBack>https://www.callback.com</CallBack></Request>"
|
||||
|
||||
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 := "<Request><Name>QueueName</Name><QueueID>" + queueID + "</QueueID><State>Active</State>" +
|
||||
"<NotifyConfig><Url>test.com</Url><State>On</State><Type>Url</Type><Event>TransCodingFinish</Event>" +
|
||||
"</NotifyConfig></Request>"
|
||||
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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user