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.

705 lines
18 KiB

  1. package cos
  2. import (
  3. "bytes"
  4. "context"
  5. "crypto/rand"
  6. "encoding/json"
  7. "encoding/xml"
  8. "fmt"
  9. "hash/crc64"
  10. "io/ioutil"
  11. "net/http"
  12. "os"
  13. "reflect"
  14. "strconv"
  15. "testing"
  16. "time"
  17. )
  18. func TestCIService_EncodePicOperations(t *testing.T) {
  19. opt := &PicOperations{
  20. IsPicInfo: 1,
  21. Rules: []PicOperationsRules{
  22. {
  23. FileId: "example.jpg",
  24. Rule: "imageView2/format/png",
  25. },
  26. },
  27. }
  28. res := EncodePicOperations(opt)
  29. jsonStr := `{"is_pic_info":1,"rules":[{"fileid":"example.jpg","rule":"imageView2/format/png"}]}`
  30. if jsonStr != res {
  31. t.Fatalf("EncodePicOperations Failed, returned:%v, want:%v", res, jsonStr)
  32. }
  33. }
  34. func TestCIService_ImageProcess(t *testing.T) {
  35. setup()
  36. defer teardown()
  37. name := "test.jpg"
  38. opt := &ImageProcessOptions{
  39. IsPicInfo: 1,
  40. Rules: []PicOperationsRules{
  41. {
  42. FileId: "format.jpg",
  43. Rule: "imageView2/format/png",
  44. },
  45. },
  46. }
  47. mux.HandleFunc("/test.jpg", func(w http.ResponseWriter, r *http.Request) {
  48. testMethod(t, r, "POST")
  49. vs := values{
  50. "image_process": "",
  51. }
  52. testFormValues(t, r, vs)
  53. header := r.Header.Get("Pic-Operations")
  54. body := new(ImageProcessOptions)
  55. err := json.Unmarshal([]byte(header), body)
  56. want := opt
  57. if err != nil {
  58. t.Errorf("CI.ImageProcess Failed: %v", err)
  59. }
  60. if !reflect.DeepEqual(want, body) {
  61. t.Errorf("CI.ImageProcess Failed, wanted:%v, body:%v", want, body)
  62. }
  63. fmt.Fprint(w, `<UploadResult>
  64. <OriginalInfo>
  65. <Key>test.jpg</Key>
  66. <Location>example-1250000000.cos.ap-guangzhou.myqcloud.com/test.jpg</Location>
  67. <ETag>&quot;8894dbe5e3ebfaf761e39b9d619c28f3327b8d85&quot;</ETag>
  68. <ImageInfo>
  69. <Format>PNG</Format>
  70. <Width>103</Width>
  71. <Height>99</Height>
  72. <Quality>100</Quality>
  73. <Ave>0xa08162</Ave>
  74. <Orientation>0</Orientation>
  75. </ImageInfo>
  76. </OriginalInfo>
  77. <ProcessResults>
  78. <Object>
  79. <Key>format.jpg</Key>
  80. <Location>example-1250000000.cos.ap-guangzhou.myqcloud.com/format.jpg</Location>
  81. <Format>PNG</Format>
  82. <Width>103</Width>
  83. <Height>99</Height>
  84. <Size>21351</Size>
  85. <Quality>100</Quality>
  86. <ETag>&quot;8894dbe5e3ebfaf761e39b9d619c28f3327b8d85&quot;</ETag>
  87. </Object>
  88. </ProcessResults>
  89. </UploadResult>`)
  90. })
  91. want := &ImageProcessResult{
  92. XMLName: xml.Name{Local: "UploadResult"},
  93. OriginalInfo: &PicOriginalInfo{
  94. Key: "test.jpg",
  95. Location: "example-1250000000.cos.ap-guangzhou.myqcloud.com/test.jpg",
  96. ETag: "\"8894dbe5e3ebfaf761e39b9d619c28f3327b8d85\"",
  97. ImageInfo: &PicImageInfo{
  98. Format: "PNG",
  99. Width: 103,
  100. Height: 99,
  101. Quality: 100,
  102. Ave: "0xa08162",
  103. Orientation: 0,
  104. },
  105. },
  106. ProcessResults: &PicProcessObject{
  107. Key: "format.jpg",
  108. Location: "example-1250000000.cos.ap-guangzhou.myqcloud.com/format.jpg",
  109. Format: "PNG",
  110. Width: 103,
  111. Height: 99,
  112. Size: 21351,
  113. Quality: 100,
  114. ETag: "\"8894dbe5e3ebfaf761e39b9d619c28f3327b8d85\"",
  115. },
  116. }
  117. res, _, err := client.CI.ImageProcess(context.Background(), name, opt)
  118. if err != nil {
  119. t.Fatalf("CI.ImageProcess returned error: %v", err)
  120. }
  121. if !reflect.DeepEqual(res, want) {
  122. t.Errorf("CI.ImageProcess failed, return:%v, want:%v", res, want)
  123. }
  124. }
  125. func TestCIService_ImageRecognition(t *testing.T) {
  126. setup()
  127. defer teardown()
  128. name := "test.jpg"
  129. detectType := "porn,terrorist,politics"
  130. mux.HandleFunc("/test.jpg", func(w http.ResponseWriter, r *http.Request) {
  131. testMethod(t, r, "GET")
  132. vs := values{
  133. "ci-process": "sensitive-content-recognition",
  134. "detect-type": "porn,terrorist,politics",
  135. }
  136. testFormValues(t, r, vs)
  137. fmt.Fprint(w, `<RecognitionResult>
  138. <PornInfo>
  139. <Code>0</Code>
  140. <Msg>OK</Msg>
  141. <HitFlag>0</HitFlag>
  142. <Score>0</Score>
  143. <Label/>
  144. </PornInfo>
  145. <TerroristInfo>
  146. <Code>0</Code>
  147. <Msg>OK</Msg>
  148. <HitFlag>0</HitFlag>
  149. <Score>0</Score>
  150. <Label/>
  151. </TerroristInfo>
  152. <PoliticsInfo>
  153. <Code>0</Code>
  154. <Msg>OK</Msg>
  155. <HitFlag>0</HitFlag>
  156. <Score>0</Score>
  157. <Label/>
  158. </PoliticsInfo>
  159. </RecognitionResult>`)
  160. })
  161. want := &ImageRecognitionResult{
  162. XMLName: xml.Name{Local: "RecognitionResult"},
  163. PornInfo: &RecognitionInfo{
  164. Code: 0,
  165. Msg: "OK",
  166. HitFlag: 0,
  167. Score: 0,
  168. },
  169. TerroristInfo: &RecognitionInfo{
  170. Code: 0,
  171. Msg: "OK",
  172. HitFlag: 0,
  173. Score: 0,
  174. },
  175. PoliticsInfo: &RecognitionInfo{
  176. Code: 0,
  177. Msg: "OK",
  178. HitFlag: 0,
  179. Score: 0,
  180. },
  181. }
  182. res, _, err := client.CI.ImageRecognition(context.Background(), name, detectType)
  183. if err != nil {
  184. t.Fatalf("CI.ImageRecognitionreturned error: %v", err)
  185. }
  186. if !reflect.DeepEqual(res, want) {
  187. t.Errorf("CI.ImageRecognition failed, return:%v, want:%v", res, want)
  188. }
  189. }
  190. func TestCIService_PutVideoAuditingJob(t *testing.T) {
  191. setup()
  192. defer teardown()
  193. name := "test.mp4"
  194. wantBody := "<Request><Input><Object>test.mp4</Object></Input>" +
  195. "<Conf><DetectType>Porn,Terrorism,Politics,Ads</DetectType>" +
  196. "<Snapshot><Mode>Interval</Mode><Count>100</Count><TimeInterval>50</TimeInterval><Start>0.5</Start></Snapshot>" +
  197. "<Callback>http://callback.com/call_back_test</Callback></Conf></Request>"
  198. mux.HandleFunc("/video/auditing", func(writer http.ResponseWriter, r *http.Request) {
  199. testMethod(t, r, http.MethodPost)
  200. testHeader(t, r, "Content-Type", "application/xml")
  201. testBody(t, r, wantBody)
  202. })
  203. opt := &PutVideoAuditingJobOptions{
  204. InputObject: name,
  205. Conf: &VideoAuditingJobConf{
  206. DetectType: "Porn,Terrorism,Politics,Ads",
  207. Snapshot: &PutVideoAuditingJobSnapshot{
  208. Mode: "Interval",
  209. Count: 100,
  210. TimeInterval: 50,
  211. Start: 0.5,
  212. },
  213. Callback: "http://callback.com/call_back_test",
  214. },
  215. }
  216. _, _, err := client.CI.PutVideoAuditingJob(context.Background(), opt)
  217. if err != nil {
  218. t.Fatalf("CI.PutVideoAuditingJob returned error: %v", err)
  219. }
  220. }
  221. func TestCIService_GetVideoAuditingJob(t *testing.T) {
  222. setup()
  223. defer teardown()
  224. jobID := "vab1ca9fc8a3ed11ea834c525400863904"
  225. mux.HandleFunc("/video/auditing"+"/"+jobID, func(w http.ResponseWriter, r *http.Request) {
  226. testMethod(t, r, http.MethodGet)
  227. })
  228. _, _, err := client.CI.GetVideoAuditingJob(context.Background(), jobID)
  229. if err != nil {
  230. t.Fatalf("CI.GetVideoAuditingJob returned error: %v", err)
  231. }
  232. }
  233. func TestCIService_PutAudioAuditingJob(t *testing.T) {
  234. setup()
  235. defer teardown()
  236. name := "test.mp4"
  237. wantBody := "<Request><Input><Object>test.mp4</Object></Input>" +
  238. "<Conf><DetectType>Porn,Terrorism,Politics,Ads</DetectType>" +
  239. "<Callback>http://callback.com/call_back_test</Callback></Conf></Request>"
  240. mux.HandleFunc("/audio/auditing", func(writer http.ResponseWriter, r *http.Request) {
  241. testMethod(t, r, http.MethodPost)
  242. testHeader(t, r, "Content-Type", "application/xml")
  243. testBody(t, r, wantBody)
  244. })
  245. opt := &PutAudioAuditingJobOptions{
  246. InputObject: name,
  247. Conf: &AudioAuditingJobConf{
  248. DetectType: "Porn,Terrorism,Politics,Ads",
  249. Callback: "http://callback.com/call_back_test",
  250. },
  251. }
  252. _, _, err := client.CI.PutAudioAuditingJob(context.Background(), opt)
  253. if err != nil {
  254. t.Fatalf("CI.PutAudioAuditingJob returned error: %v", err)
  255. }
  256. }
  257. func TestCIService_GetAudioAuditingJob(t *testing.T) {
  258. setup()
  259. defer teardown()
  260. jobID := "vab1ca9fc8a3ed11ea834c525400863904"
  261. mux.HandleFunc("/audio/auditing"+"/"+jobID, func(w http.ResponseWriter, r *http.Request) {
  262. testMethod(t, r, http.MethodGet)
  263. })
  264. _, _, err := client.CI.GetAudioAuditingJob(context.Background(), jobID)
  265. if err != nil {
  266. t.Fatalf("CI.GetAudioAuditingJob returned error: %v", err)
  267. }
  268. }
  269. func TestCIService_Put(t *testing.T) {
  270. setup()
  271. defer teardown()
  272. name := "test.jpg"
  273. data := make([]byte, 1024*1024*3)
  274. rand.Read(data)
  275. pic := &ImageProcessOptions{
  276. IsPicInfo: 1,
  277. Rules: []PicOperationsRules{
  278. {
  279. FileId: "format.jpg",
  280. Rule: "imageView2/format/png",
  281. },
  282. },
  283. }
  284. mux.HandleFunc("/test.jpg", func(w http.ResponseWriter, r *http.Request) {
  285. testMethod(t, r, "PUT")
  286. header := r.Header.Get("Pic-Operations")
  287. body := new(ImageProcessOptions)
  288. err := json.Unmarshal([]byte(header), body)
  289. want := pic
  290. if err != nil {
  291. t.Errorf("CI.Put Failed: %v", err)
  292. }
  293. if !reflect.DeepEqual(want, body) {
  294. t.Errorf("CI.Put Failed, wanted:%v, body:%v", want, body)
  295. }
  296. tb := crc64.MakeTable(crc64.ECMA)
  297. ht := crc64.New(tb)
  298. tr := TeeReader(r.Body, ht, 0, nil)
  299. bs, err := ioutil.ReadAll(tr)
  300. if err != nil {
  301. t.Errorf("CI.Put ReadAll Failed: %v", err)
  302. }
  303. if bytes.Compare(bs, data) != 0 {
  304. t.Errorf("CI.Put Failed, data isn't consistent")
  305. }
  306. crc := tr.Crc64()
  307. w.Header().Add("x-cos-hash-crc64ecma", strconv.FormatUint(crc, 10))
  308. fmt.Fprint(w, `<UploadResult>
  309. <OriginalInfo>
  310. <Key>test.jpg</Key>
  311. <Location>example-1250000000.cos.ap-guangzhou.myqcloud.com/test.jpg</Location>
  312. <ETag>&quot;8894dbe5e3ebfaf761e39b9d619c28f3327b8d85&quot;</ETag>
  313. <ImageInfo>
  314. <Format>PNG</Format>
  315. <Width>103</Width>
  316. <Height>99</Height>
  317. <Quality>100</Quality>
  318. <Ave>0xa08162</Ave>
  319. <Orientation>0</Orientation>
  320. </ImageInfo>
  321. </OriginalInfo>
  322. <ProcessResults>
  323. <Object>
  324. <Key>format.jpg</Key>
  325. <Location>example-1250000000.cos.ap-guangzhou.myqcloud.com/format.jpg</Location>
  326. <Format>PNG</Format>
  327. <Width>103</Width>
  328. <Height>99</Height>
  329. <Size>21351</Size>
  330. <Quality>100</Quality>
  331. <ETag>&quot;8894dbe5e3ebfaf761e39b9d619c28f3327b8d85&quot;</ETag>
  332. </Object>
  333. </ProcessResults>
  334. </UploadResult>`)
  335. })
  336. want := &ImageProcessResult{
  337. XMLName: xml.Name{Local: "UploadResult"},
  338. OriginalInfo: &PicOriginalInfo{
  339. Key: "test.jpg",
  340. Location: "example-1250000000.cos.ap-guangzhou.myqcloud.com/test.jpg",
  341. ETag: "\"8894dbe5e3ebfaf761e39b9d619c28f3327b8d85\"",
  342. ImageInfo: &PicImageInfo{
  343. Format: "PNG",
  344. Width: 103,
  345. Height: 99,
  346. Quality: 100,
  347. Ave: "0xa08162",
  348. Orientation: 0,
  349. },
  350. },
  351. ProcessResults: &PicProcessObject{
  352. Key: "format.jpg",
  353. Location: "example-1250000000.cos.ap-guangzhou.myqcloud.com/format.jpg",
  354. Format: "PNG",
  355. Width: 103,
  356. Height: 99,
  357. Size: 21351,
  358. Quality: 100,
  359. ETag: "\"8894dbe5e3ebfaf761e39b9d619c28f3327b8d85\"",
  360. },
  361. }
  362. f := bytes.NewReader(data)
  363. opt := &ObjectPutOptions{
  364. nil,
  365. &ObjectPutHeaderOptions{
  366. XOptionHeader: &http.Header{},
  367. },
  368. }
  369. opt.XOptionHeader.Add("Pic-Operations", EncodePicOperations(pic))
  370. res, _, err := client.CI.Put(context.Background(), name, f, opt)
  371. if err != nil {
  372. t.Fatalf("CI.Put returned error: %v", err)
  373. }
  374. if !reflect.DeepEqual(res, want) {
  375. t.Errorf("CI.ImageProcess failed, return:%v, want:%v", res, want)
  376. }
  377. }
  378. func TestCIService_PutFromFile(t *testing.T) {
  379. setup()
  380. defer teardown()
  381. name := "test.jpg"
  382. filePath := "test.file" + time.Now().Format(time.RFC3339)
  383. newfile, err := os.Create(filePath)
  384. if err != nil {
  385. t.Fatalf("creat tmp file failed")
  386. }
  387. defer os.Remove(filePath)
  388. data := make([]byte, 1024*1024*3)
  389. rand.Read(data)
  390. newfile.Write(data)
  391. newfile.Close()
  392. pic := &ImageProcessOptions{
  393. IsPicInfo: 1,
  394. Rules: []PicOperationsRules{
  395. {
  396. FileId: "format.jpg",
  397. Rule: "imageView2/format/png",
  398. },
  399. },
  400. }
  401. mux.HandleFunc("/test.jpg", func(w http.ResponseWriter, r *http.Request) {
  402. testMethod(t, r, "PUT")
  403. header := r.Header.Get("Pic-Operations")
  404. body := new(ImageProcessOptions)
  405. err := json.Unmarshal([]byte(header), body)
  406. want := pic
  407. if err != nil {
  408. t.Errorf("CI.Put Failed: %v", err)
  409. }
  410. if !reflect.DeepEqual(want, body) {
  411. t.Errorf("CI.Put Failed, wanted:%v, body:%v", want, body)
  412. }
  413. tb := crc64.MakeTable(crc64.ECMA)
  414. ht := crc64.New(tb)
  415. tr := TeeReader(r.Body, ht, 0, nil)
  416. bs, err := ioutil.ReadAll(tr)
  417. if err != nil {
  418. t.Errorf("CI.Put ReadAll Failed: %v", err)
  419. }
  420. if bytes.Compare(bs, data) != 0 {
  421. t.Errorf("CI.Put Failed, data isn't consistent")
  422. }
  423. crc := tr.Crc64()
  424. w.Header().Add("x-cos-hash-crc64ecma", strconv.FormatUint(crc, 10))
  425. fmt.Fprint(w, `<UploadResult>
  426. <OriginalInfo>
  427. <Key>test.jpg</Key>
  428. <Location>example-1250000000.cos.ap-guangzhou.myqcloud.com/test.jpg</Location>
  429. <ETag>&quot;8894dbe5e3ebfaf761e39b9d619c28f3327b8d85&quot;</ETag>
  430. <ImageInfo>
  431. <Format>PNG</Format>
  432. <Width>103</Width>
  433. <Height>99</Height>
  434. <Quality>100</Quality>
  435. <Ave>0xa08162</Ave>
  436. <Orientation>0</Orientation>
  437. </ImageInfo>
  438. </OriginalInfo>
  439. <ProcessResults>
  440. <Object>
  441. <Key>format.jpg</Key>
  442. <Location>example-1250000000.cos.ap-guangzhou.myqcloud.com/format.jpg</Location>
  443. <Format>PNG</Format>
  444. <Width>103</Width>
  445. <Height>99</Height>
  446. <Size>21351</Size>
  447. <Quality>100</Quality>
  448. <ETag>&quot;8894dbe5e3ebfaf761e39b9d619c28f3327b8d85&quot;</ETag>
  449. </Object>
  450. </ProcessResults>
  451. </UploadResult>`)
  452. })
  453. want := &ImageProcessResult{
  454. XMLName: xml.Name{Local: "UploadResult"},
  455. OriginalInfo: &PicOriginalInfo{
  456. Key: "test.jpg",
  457. Location: "example-1250000000.cos.ap-guangzhou.myqcloud.com/test.jpg",
  458. ETag: "\"8894dbe5e3ebfaf761e39b9d619c28f3327b8d85\"",
  459. ImageInfo: &PicImageInfo{
  460. Format: "PNG",
  461. Width: 103,
  462. Height: 99,
  463. Quality: 100,
  464. Ave: "0xa08162",
  465. Orientation: 0,
  466. },
  467. },
  468. ProcessResults: &PicProcessObject{
  469. Key: "format.jpg",
  470. Location: "example-1250000000.cos.ap-guangzhou.myqcloud.com/format.jpg",
  471. Format: "PNG",
  472. Width: 103,
  473. Height: 99,
  474. Size: 21351,
  475. Quality: 100,
  476. ETag: "\"8894dbe5e3ebfaf761e39b9d619c28f3327b8d85\"",
  477. },
  478. }
  479. opt := &ObjectPutOptions{
  480. nil,
  481. &ObjectPutHeaderOptions{
  482. XOptionHeader: &http.Header{},
  483. },
  484. }
  485. opt.XOptionHeader.Add("Pic-Operations", EncodePicOperations(pic))
  486. res, _, err := client.CI.PutFromFile(context.Background(), name, filePath, opt)
  487. if err != nil {
  488. t.Fatalf("CI.Put returned error: %v", err)
  489. }
  490. if !reflect.DeepEqual(res, want) {
  491. t.Errorf("CI.ImageProcess failed, return:%v, want:%v", res, want)
  492. }
  493. }
  494. func TestCIService_Get(t *testing.T) {
  495. setup()
  496. defer teardown()
  497. mux.HandleFunc("/test.jpg", func(w http.ResponseWriter, r *http.Request) {
  498. testMethod(t, r, http.MethodGet)
  499. vs := values{
  500. "imageMogr2/thumbnail/!50p": "",
  501. }
  502. testFormValues(t, r, vs)
  503. })
  504. _, err := client.CI.Get(context.Background(), "test.jpg", "imageMogr2/thumbnail/!50p", nil)
  505. if err != nil {
  506. t.Fatalf("CI.Get returned error: %v", err)
  507. }
  508. }
  509. func TestCIService_GetToFile(t *testing.T) {
  510. setup()
  511. defer teardown()
  512. mux.HandleFunc("/test.jpg", func(w http.ResponseWriter, r *http.Request) {
  513. testMethod(t, r, http.MethodGet)
  514. vs := values{
  515. "imageMogr2/thumbnail/!50p": "",
  516. }
  517. testFormValues(t, r, vs)
  518. })
  519. filepath := "test.jpg." + time.Now().Format(time.RFC3339)
  520. defer os.Remove(filepath)
  521. _, err := client.CI.GetToFile(context.Background(), "test.jpg", filepath, "imageMogr2/thumbnail/!50p", nil)
  522. if err != nil {
  523. t.Fatalf("CI.GetToFile returned error: %v", err)
  524. }
  525. }
  526. func TestCIService_GetQRcode(t *testing.T) {
  527. setup()
  528. defer teardown()
  529. mux.HandleFunc("/test.jpg", func(w http.ResponseWriter, r *http.Request) {
  530. testMethod(t, r, http.MethodGet)
  531. vs := values{
  532. "ci-process": "QRcode",
  533. "cover": "1",
  534. }
  535. testFormValues(t, r, vs)
  536. })
  537. _, _, err := client.CI.GetQRcode(context.Background(), "test.jpg", 1, nil)
  538. if err != nil {
  539. t.Fatalf("CI.GetQRcode returned error: %v", err)
  540. }
  541. }
  542. func TestCIService_GenerateQRcode(t *testing.T) {
  543. setup()
  544. defer teardown()
  545. mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
  546. testMethod(t, r, http.MethodGet)
  547. vs := values{
  548. "ci-process": "qrcode-generate",
  549. "qrcode-content": "<https://www.example.com>",
  550. "mode": "1",
  551. "width": "200",
  552. }
  553. testFormValues(t, r, vs)
  554. })
  555. opt := &GenerateQRcodeOptions{
  556. QRcodeContent: "<https://www.example.com>",
  557. Mode: 1,
  558. Width: 200,
  559. }
  560. _, _, err := client.CI.GenerateQRcode(context.Background(), opt)
  561. if err != nil {
  562. t.Fatalf("CI.GenerateQRcode returned error: %v", err)
  563. }
  564. }
  565. func TestCIService_GenerateQRcodeToFile(t *testing.T) {
  566. setup()
  567. defer teardown()
  568. mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
  569. testMethod(t, r, http.MethodGet)
  570. vs := values{
  571. "ci-process": "qrcode-generate",
  572. "qrcode-content": "<https://www.example.com>",
  573. "mode": "1",
  574. "width": "200",
  575. }
  576. testFormValues(t, r, vs)
  577. })
  578. opt := &GenerateQRcodeOptions{
  579. QRcodeContent: "<https://www.example.com>",
  580. Mode: 1,
  581. Width: 200,
  582. }
  583. filepath := "test.file." + time.Now().Format(time.RFC3339)
  584. defer os.Remove(filepath)
  585. _, _, err := client.CI.GenerateQRcodeToFile(context.Background(), filepath, opt)
  586. if err != nil {
  587. t.Fatalf("CI.GenerateQRcode returned error: %v", err)
  588. }
  589. }
  590. func TestBucketService_GetGuetzli(t *testing.T) {
  591. setup()
  592. defer teardown()
  593. mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
  594. testMethod(t, r, "GET")
  595. vs := values{
  596. "guetzli": "",
  597. }
  598. testFormValues(t, r, vs)
  599. fmt.Fprint(w, `<GuetzliStatus>on</GuetzliStatus>`)
  600. })
  601. res, _, err := client.CI.GetGuetzli(context.Background())
  602. if err != nil {
  603. t.Fatalf("CI.GetGuetzli returned error %v", err)
  604. }
  605. want := &GetGuetzliResult{
  606. XMLName: xml.Name{Local: "GuetzliStatus"},
  607. GuetzliStatus: "on",
  608. }
  609. if !reflect.DeepEqual(res, want) {
  610. t.Errorf("CI.GetGuetzli %+v, want %+v", res, want)
  611. }
  612. }
  613. func TestBucketService_PutGuetzli(t *testing.T) {
  614. setup()
  615. defer teardown()
  616. mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
  617. testMethod(t, r, "PUT")
  618. vs := values{
  619. "guetzli": "",
  620. }
  621. testFormValues(t, r, vs)
  622. })
  623. _, err := client.CI.PutGuetzli(context.Background())
  624. if err != nil {
  625. t.Fatalf("CI.PutGuetzli returned error: %v", err)
  626. }
  627. }
  628. func TestBucketService_DeleteGuetzli(t *testing.T) {
  629. setup()
  630. defer teardown()
  631. mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
  632. testMethod(t, r, "DELETE")
  633. vs := values{
  634. "guetzli": "",
  635. }
  636. testFormValues(t, r, vs)
  637. w.WriteHeader(http.StatusNoContent)
  638. })
  639. _, err := client.CI.DeleteGuetzli(context.Background())
  640. if err != nil {
  641. t.Fatalf("CI.PutGuetzli returned error: %v", err)
  642. }
  643. }