Skip to content

Commit 30100a6

Browse files
committed
文件处理单应测试
1 parent 839e8b7 commit 30100a6

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

ci_fileprocess_test.go

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package cos
2+
3+
import (
4+
"context"
5+
"net/http"
6+
"testing"
7+
)
8+
9+
func TestCIService_CreateFileProcessJob(t *testing.T) {
10+
setup()
11+
defer teardown()
12+
wantBody := "<Request><Tag>FileHashCode</Tag><Input><Object>294028.zip</Object></Input>" +
13+
"<Operation><FileHashCodeConfig><Type>sha1</Type><AddToHeader>true</AddToHeader>" +
14+
"</FileHashCodeConfig></Operation><QueueId>pb6a88aead4dd4fa8bc953d4ca4e04430</QueueId></Request>"
15+
16+
mux.HandleFunc("/file_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+
22+
createJobOpt := &FileProcessJobOptions{
23+
Tag: "FileHashCode",
24+
Input: &FileProcessInput{
25+
Object: "294028.zip",
26+
},
27+
Operation: &FileProcessJobOperation{
28+
FileHashCodeConfig: &FileHashCodeConfig{
29+
Type: "sha1",
30+
AddToHeader: true,
31+
},
32+
},
33+
QueueId: "pb6a88aead4dd4fa8bc953d4ca4e04430",
34+
}
35+
36+
_, _, err := client.CI.CreateFileProcessJob(context.Background(), createJobOpt)
37+
if err != nil {
38+
t.Fatalf("CI.CreateFileProcessJob returned error: %v", err)
39+
}
40+
}
41+
42+
func TestCIService_DescribeFileProcessJob(t *testing.T) {
43+
setup()
44+
defer teardown()
45+
46+
jobID := "f9640f1b0874211edb47e5fa2d6bd5e47"
47+
mux.HandleFunc("/file_jobs"+"/"+jobID, func(w http.ResponseWriter, r *http.Request) {
48+
testMethod(t, r, http.MethodGet)
49+
})
50+
51+
_, _, err := client.CI.DescribeFileProcessJob(context.Background(), jobID)
52+
53+
if err != nil {
54+
t.Fatalf("CI.DescribeFileProcessJob returned error: %v", err)
55+
}
56+
}
57+
58+
func TestCIService_GetFileHash(t *testing.T) {
59+
setup()
60+
defer teardown()
61+
62+
name := "sample.pdf"
63+
mux.HandleFunc("/"+name, func(w http.ResponseWriter, r *http.Request) {
64+
testMethod(t, r, http.MethodGet)
65+
v := values{
66+
"ci-process": "filehash",
67+
"type": "sha1",
68+
"addtoheader": "true",
69+
}
70+
testFormValues(t, r, v)
71+
})
72+
73+
opt := &GetFileHashOptions{
74+
CIProcess: "filehash",
75+
Type: "sha1",
76+
AddToHeader: true,
77+
}
78+
79+
_, _, err := client.CI.GetFileHash(context.Background(), name, opt)
80+
if err != nil {
81+
t.Fatalf("CI.GetFileHash returned error: %v", err)
82+
}
83+
}

0 commit comments

Comments
 (0)