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.

67 lines
1.5 KiB

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