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.

88 lines
1.9 KiB

  1. package cos
  2. import (
  3. "context"
  4. "encoding/xml"
  5. "fmt"
  6. "net/http"
  7. "reflect"
  8. "testing"
  9. )
  10. func TestBucketService_GetReferer(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. "referer": "",
  17. }
  18. testFormValues(t, r, vs)
  19. fmt.Fprint(w, `<RefererConfiguration>
  20. <Status>Enabled</Status>
  21. <RefererType>White-List</RefererType>
  22. <DomainList>
  23. <Domain>*.qq.com</Domain>
  24. <Domain>*.qcloud.com</Domain>
  25. </DomainList>
  26. <EmptyReferConfiguration>Allow</EmptyReferConfiguration>
  27. </RefererConfiguration>`)
  28. })
  29. res, _, err := client.Bucket.GetReferer(context.Background())
  30. if err != nil {
  31. t.Fatalf("Bucket.GetReferer returned error %v", err)
  32. }
  33. want := &BucketGetRefererResult{
  34. XMLName: xml.Name{Local: "RefererConfiguration"},
  35. Status: "Enabled",
  36. RefererType: "White-List",
  37. DomainList: []string{
  38. "*.qq.com",
  39. "*.qcloud.com",
  40. },
  41. EmptyReferConfiguration: "Allow",
  42. }
  43. if !reflect.DeepEqual(res, want) {
  44. t.Errorf("Bucket.GetReferer returned %+v, want %+v", res, want)
  45. }
  46. }
  47. func TestBucketService_PutReferer(t *testing.T) {
  48. setup()
  49. defer teardown()
  50. opt := &BucketPutRefererOptions{
  51. Status: "Enabled",
  52. RefererType: "White-List",
  53. DomainList: []string{
  54. "*.qq.com",
  55. "*.qcloud.com",
  56. },
  57. EmptyReferConfiguration: "Allow",
  58. }
  59. mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
  60. testMethod(t, r, "PUT")
  61. vs := values{
  62. "referer": "",
  63. }
  64. testFormValues(t, r, vs)
  65. body := new(BucketPutRefererOptions)
  66. xml.NewDecoder(r.Body).Decode(body)
  67. want := opt
  68. want.XMLName = xml.Name{Local: "RefererConfiguration"}
  69. if !reflect.DeepEqual(body, want) {
  70. t.Errorf("Bucket.PutReferer request\n body: %+v\nwant %+v\n", body, want)
  71. }
  72. })
  73. _, err := client.Bucket.PutReferer(context.Background(), opt)
  74. if err != nil {
  75. t.Fatalf("Bucket.PutReferer returned error: %v", err)
  76. }
  77. }