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.

56 lines
1.7 KiB

  1. package cos
  2. import (
  3. "fmt"
  4. "net/http"
  5. "testing"
  6. )
  7. // func Test_checkResponse_error(t *testing.T) {
  8. // setup()
  9. // defer teardown()
  10. // mux.HandleFunc("/test_409", func(w http.ResponseWriter, r *http.Request) {
  11. // w.WriteHeader(http.StatusConflict)
  12. // fmt.Fprint(w, `<?xml version='1.0' encoding='utf-8' ?>
  13. // <Error>
  14. // <Code>BucketAlreadyExists</Code>
  15. // <Message>The requested bucket name is not available.</Message>
  16. // <Resource>testdelete-1253846586.cos.ap-guangzhou.myqcloud.com</Resource>
  17. // <RequestId>NTk0NTRjZjZfNTViMjM1XzlkMV9hZTZh</RequestId>
  18. // <TraceId>OGVmYzZiMmQzYjA2OWNhODk0NTRkMTBiOWVmMDAxODc0OWRkZjk0ZDM1NmI1M2E2MTRlY2MzZDhmNmI5MWI1OTBjYzE2MjAxN2M1MzJiOTdkZjMxMDVlYTZjN2FiMmI0NTk3NWFiNjAyMzdlM2RlMmVmOGNiNWIxYjYwNDFhYmQ=</TraceId>
  19. // </Error>`)
  20. // })
  21. // req, _ := http.NewRequest("GET", client.BaseURL.ServiceURL.String()+"/test_409", nil)
  22. // resp, _ := client.client.Do(req)
  23. // err := checkResponse(resp)
  24. // if e, ok := err.(*ErrorResponse); ok {
  25. // if e.Error() == "" {
  26. // t.Errorf("Expected e.Error() not empty, got %+v", e.Error())
  27. // }
  28. // if e.Code != "BucketAlreadyExists" {
  29. // t.Errorf("Expected BucketAlreadyExists error, got %+v", e.Code)
  30. // }
  31. // } else {
  32. // t.Errorf("Expected ErrorResponse error, got %+v", err)
  33. // }
  34. // }
  35. func Test_checkResponse_no_error(t *testing.T) {
  36. setup()
  37. defer teardown()
  38. mux.HandleFunc("/test_200", func(w http.ResponseWriter, r *http.Request) {
  39. fmt.Fprint(w, `test`)
  40. })
  41. req, _ := http.NewRequest("GET", client.BaseURL.ServiceURL.String()+"/test_200", nil)
  42. resp, _ := client.client.Do(req)
  43. err := checkResponse(resp)
  44. if err != nil {
  45. t.Errorf("Expected error == nil, got %+v", err)
  46. }
  47. }