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.

76 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_PutIntelligentTiering(t *testing.T) {
  11. setup()
  12. defer teardown()
  13. opt := &BucketPutIntelligentTieringOptions{
  14. Status: "Enabled",
  15. Transition: &BucketIntelligentTieringTransition{
  16. Days: 30,
  17. },
  18. }
  19. mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
  20. testMethod(t, r, http.MethodPut)
  21. vs := values{
  22. "intelligenttiering": "",
  23. }
  24. testFormValues(t, r, vs)
  25. body := &BucketPutIntelligentTieringOptions{}
  26. xml.NewDecoder(r.Body).Decode(body)
  27. want := opt
  28. want.XMLName = xml.Name{Local: "IntelligentTieringConfiguration"}
  29. if !reflect.DeepEqual(want, body) {
  30. t.Fatalf("Bucket.PutIntelligentTiering request\n body: %+v\n, want %+v\n", body, want)
  31. }
  32. })
  33. _, err := client.Bucket.PutIntelligentTiering(context.Background(), opt)
  34. if err != nil {
  35. t.Fatalf("Bucket.PutIntelligentTiering failed, error: %v", err)
  36. }
  37. }
  38. func TestBucketService_GetIntelligentTiering(t *testing.T) {
  39. setup()
  40. defer teardown()
  41. mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
  42. testMethod(t, r, http.MethodGet)
  43. vs := values{
  44. "intelligenttiering": "",
  45. }
  46. testFormValues(t, r, vs)
  47. fmt.Fprint(w, `<IntelligentTieringConfiguration>
  48. <Status>Enabled</Status>
  49. <Transition>
  50. <Days>30</Days>
  51. </Transition>
  52. </IntelligentTieringConfiguration>`)
  53. })
  54. res, _, err := client.Bucket.GetIntelligentTiering(context.Background())
  55. if err != nil {
  56. t.Fatalf("Bucket.GetIntelligentTiering failed, error: %v", err)
  57. }
  58. want := &BucketGetIntelligentTieringResult{
  59. XMLName: xml.Name{Local: "IntelligentTieringConfiguration"},
  60. Status: "Enabled",
  61. Transition: &BucketIntelligentTieringTransition{
  62. Days: 30,
  63. },
  64. }
  65. if !reflect.DeepEqual(res, want) {
  66. t.Errorf("Bucket.GetIntelligentTiering returned\n%+v, want\n%+v", res, want)
  67. }
  68. }