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.

66 lines
1.4 KiB

4 years ago
4 years ago
  1. package cos
  2. import (
  3. "context"
  4. "encoding/xml"
  5. "fmt"
  6. "net/http"
  7. "reflect"
  8. "testing"
  9. )
  10. func TestServiceService_Get(t *testing.T) {
  11. setup()
  12. defer teardown()
  13. mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
  14. testMethod(t, r, "GET")
  15. fmt.Fprint(w, `<ListAllMyBucketsResult>
  16. <Owner>
  17. <ID>xbaccxx</ID>
  18. <DisplayName>100000760461</DisplayName>
  19. </Owner>
  20. <Buckets>
  21. <Bucket>
  22. <Name>huadong-1253846586</Name>
  23. <Location>ap-shanghai</Location>
  24. <CreationDate>2017-06-16T13:08:28Z</CreationDate>
  25. </Bucket>
  26. <Bucket>
  27. <Name>huanan-1253846586</Name>
  28. <Location>ap-guangzhou</Location>
  29. <CreationDate>2017-06-10T09:00:07Z</CreationDate>
  30. </Bucket>
  31. </Buckets>
  32. </ListAllMyBucketsResult>`)
  33. })
  34. ref, _, err := client.Service.Get(context.Background())
  35. if err != nil {
  36. t.Fatalf("Service.Get returned error: %v", err)
  37. }
  38. want := &ServiceGetResult{
  39. XMLName: xml.Name{Local: "ListAllMyBucketsResult"},
  40. Owner: &Owner{
  41. ID: "xbaccxx",
  42. DisplayName: "100000760461",
  43. },
  44. Buckets: []Bucket{
  45. {
  46. Name: "huadong-1253846586",
  47. Region: "ap-shanghai",
  48. CreationDate: "2017-06-16T13:08:28Z",
  49. },
  50. {
  51. Name: "huanan-1253846586",
  52. Region: "ap-guangzhou",
  53. CreationDate: "2017-06-10T09:00:07Z",
  54. },
  55. },
  56. }
  57. if !reflect.DeepEqual(ref, want) {
  58. t.Errorf("Service.Get returned %+v, want %+v", ref, want)
  59. }
  60. }