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.

75 lines
1.7 KiB

  1. package cos
  2. import (
  3. "context"
  4. "encoding/xml"
  5. "fmt"
  6. "net/http"
  7. "reflect"
  8. "testing"
  9. )
  10. func TestBucketService_PutLogging(t *testing.T) {
  11. setup()
  12. defer teardown()
  13. opt := &BucketPutLoggingOptions{
  14. LoggingEnabled: &BucketLoggingEnabled{
  15. TargetBucket: "logs",
  16. },
  17. }
  18. mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
  19. testMethod(t, r, http.MethodPut)
  20. vs := values{
  21. "logging": "",
  22. }
  23. testFormValues(t, r, vs)
  24. body := &BucketPutLoggingOptions{}
  25. xml.NewDecoder(r.Body).Decode(body)
  26. want := opt
  27. want.XMLName = xml.Name{Local: "BucketLoggingStatus"}
  28. if !reflect.DeepEqual(want, body) {
  29. t.Fatalf("Bucket.PutLogging request\n body: %+v\n, want %+v\n", body, want)
  30. }
  31. })
  32. _, err := client.Bucket.PutLogging(context.Background(), opt)
  33. if err != nil {
  34. t.Fatalf("Bucket.PutLogging failed, error: %v", err)
  35. }
  36. }
  37. func TestBucketService_GetLogging(t *testing.T) {
  38. setup()
  39. defer teardown()
  40. mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
  41. testMethod(t, r, http.MethodGet)
  42. vs := values{
  43. "logging": "",
  44. }
  45. testFormValues(t, r, vs)
  46. fmt.Fprint(w, `<BucketLoggingStatus>
  47. <LoggingEnabled>
  48. <TargetBucket>logs</TargetBucket>
  49. <TargetPrefix>mylogs</TargetPrefix>
  50. </LoggingEnabled>
  51. </BucketLoggingStatus>`)
  52. })
  53. res, _, err := client.Bucket.GetLogging(context.Background())
  54. if err != nil {
  55. t.Fatalf("Bucket.GetLogging failed, error: %v", err)
  56. }
  57. want := &BucketGetLoggingResult{
  58. XMLName: xml.Name{Local: "BucketLoggingStatus"},
  59. LoggingEnabled: &BucketLoggingEnabled{
  60. TargetBucket: "logs",
  61. TargetPrefix: "mylogs",
  62. },
  63. }
  64. if !reflect.DeepEqual(res, want) {
  65. t.Errorf("Bucket.GetLogging returned\n%+v, want\n%+v", res, want)
  66. }
  67. }