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.

74 lines
1.6 KiB

  1. package cos
  2. import (
  3. "context"
  4. "encoding/xml"
  5. "fmt"
  6. "net/http"
  7. "reflect"
  8. "testing"
  9. )
  10. func TestBucketService_GetAccelerate(t *testing.T) {
  11. setup()
  12. defer teardown()
  13. mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
  14. testMethod(t, r, "GET")
  15. vs := values{
  16. "accelerate": "",
  17. }
  18. testFormValues(t, r, vs)
  19. fmt.Fprint(w, `<AccelerateConfiguration>
  20. <Status>Enabled</Status>
  21. <Type>COS</Type>
  22. </AccelerateConfiguration>`)
  23. })
  24. res, _, err := client.Bucket.GetAccelerate(context.Background())
  25. if err != nil {
  26. t.Fatalf("Bucket.GetAccelerate returned error %v", err)
  27. }
  28. want := &BucketGetAccelerateResult{
  29. XMLName: xml.Name{Local: "AccelerateConfiguration"},
  30. Status: "Enabled",
  31. Type: "COS",
  32. }
  33. if !reflect.DeepEqual(res, want) {
  34. t.Errorf("Bucket.GetAccelerate returned %+v, want %+v", res, want)
  35. }
  36. }
  37. func TestBucketService_PutAccelerate(t *testing.T) {
  38. setup()
  39. defer teardown()
  40. opt := &BucketPutAccelerateOptions{
  41. XMLName: xml.Name{Local: "AccelerateConfiguration"},
  42. Status: "Enabled",
  43. Type: "COS",
  44. }
  45. mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
  46. testMethod(t, r, "PUT")
  47. vs := values{
  48. "accelerate": "",
  49. }
  50. testFormValues(t, r, vs)
  51. body := new(BucketPutAccelerateOptions)
  52. xml.NewDecoder(r.Body).Decode(body)
  53. want := opt
  54. want.XMLName = xml.Name{Local: "AccelerateConfiguration"}
  55. if !reflect.DeepEqual(body, want) {
  56. t.Errorf("Bucket.PutAccelerate request\n body: %+v\n, want %+v\n", body, want)
  57. }
  58. })
  59. _, err := client.Bucket.PutAccelerate(context.Background(), opt)
  60. if err != nil {
  61. t.Fatalf("Bucket.PutAccelerate returned error: %v", err)
  62. }
  63. }