Skip to content

Commit 4ed001c

Browse files
author
wanjiewu
committed
支持云上处理能力设置自定义header&单测
1 parent d4cc963 commit 4ed001c

File tree

1 file changed

+100
-0
lines changed

1 file changed

+100
-0
lines changed

ci_test.go

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,106 @@ func TestCIService_ImageProcess(t *testing.T) {
139139
}
140140
}
141141

142+
func TestCIService_ImageProcessWithHeader(t *testing.T) {
143+
setup()
144+
defer teardown()
145+
name := "test.jpg"
146+
147+
opt := &ImageProcessOptions{
148+
IsPicInfo: 1,
149+
Rules: []PicOperationsRules{
150+
{
151+
FileId: "format.jpg",
152+
Rule: "imageView2/format/png",
153+
},
154+
},
155+
}
156+
157+
mux.HandleFunc("/test.jpg", func(w http.ResponseWriter, r *http.Request) {
158+
testMethod(t, r, "POST")
159+
vs := values{
160+
"image_process": "",
161+
}
162+
testFormValues(t, r, vs)
163+
header := r.Header.Get("Pic-Operations")
164+
body := new(ImageProcessOptions)
165+
err := json.Unmarshal([]byte(header), body)
166+
want := opt
167+
if err != nil {
168+
t.Errorf("CI.ImageProcess Failed: %v", err)
169+
}
170+
if !reflect.DeepEqual(want, body) {
171+
t.Errorf("CI.ImageProcess Failed, wanted:%v, body:%v", want, body)
172+
}
173+
fmt.Fprint(w, `<UploadResult>
174+
<OriginalInfo>
175+
<Key>test.jpg</Key>
176+
<Location>example-1250000000.cos.ap-guangzhou.myqcloud.com/test.jpg</Location>
177+
<ETag>&quot;8894dbe5e3ebfaf761e39b9d619c28f3327b8d85&quot;</ETag>
178+
<ImageInfo>
179+
<Format>PNG</Format>
180+
<Width>103</Width>
181+
<Height>99</Height>
182+
<Quality>100</Quality>
183+
<Ave>0xa08162</Ave>
184+
<Orientation>0</Orientation>
185+
</ImageInfo>
186+
</OriginalInfo>
187+
<ProcessResults>
188+
<Object>
189+
<Key>format.jpg</Key>
190+
<Location>example-1250000000.cos.ap-guangzhou.myqcloud.com/format.jpg</Location>
191+
<Format>PNG</Format>
192+
<Width>103</Width>
193+
<Height>99</Height>
194+
<Size>21351</Size>
195+
<Quality>100</Quality>
196+
<ETag>&quot;8894dbe5e3ebfaf761e39b9d619c28f3327b8d85&quot;</ETag>
197+
</Object>
198+
</ProcessResults>
199+
</UploadResult>`)
200+
})
201+
202+
want := &ImageProcessResult{
203+
XMLName: xml.Name{Local: "UploadResult"},
204+
OriginalInfo: &PicOriginalInfo{
205+
Key: "test.jpg",
206+
Location: "example-1250000000.cos.ap-guangzhou.myqcloud.com/test.jpg",
207+
ETag: "\"8894dbe5e3ebfaf761e39b9d619c28f3327b8d85\"",
208+
ImageInfo: &PicImageInfo{
209+
Format: "PNG",
210+
Width: 103,
211+
Height: 99,
212+
Quality: 100,
213+
Ave: "0xa08162",
214+
Orientation: 0,
215+
},
216+
},
217+
ProcessResults: []PicProcessObject{
218+
{
219+
Key: "format.jpg",
220+
Location: "example-1250000000.cos.ap-guangzhou.myqcloud.com/format.jpg",
221+
Format: "PNG",
222+
Width: 103,
223+
Height: 99,
224+
Size: 21351,
225+
Quality: 100,
226+
ETag: "\"8894dbe5e3ebfaf761e39b9d619c28f3327b8d85\"",
227+
},
228+
},
229+
}
230+
optHeader := &ImageProcessHeader{
231+
PicOperations: EncodePicOperations(opt),
232+
}
233+
res, _, err := client.CI.ImageProcessWithHeader(context.Background(), name, optHeader)
234+
if err != nil {
235+
t.Fatalf("CI.ImageProcess returned error: %v", err)
236+
}
237+
if !reflect.DeepEqual(res, want) {
238+
t.Errorf("CI.ImageProcess failed, return:%v, want:%v", res, want)
239+
}
240+
}
241+
142242
func TestCIService_ImageRecognition(t *testing.T) {
143243
setup()
144244
defer teardown()

0 commit comments

Comments
 (0)