(t *testing.T)
| 3855 | } |
| 3856 | |
| 3857 | func TestCheckResponse_unexpectedErrorStructure(t *testing.T) { |
| 3858 | t.Parallel() |
| 3859 | httpBody := `{"message":"m", "errors": ["error 1"]}` |
| 3860 | res := &http.Response{ |
| 3861 | Request: &http.Request{}, |
| 3862 | StatusCode: http.StatusBadRequest, |
| 3863 | Body: io.NopCloser(strings.NewReader(httpBody)), |
| 3864 | } |
| 3865 | var err *ErrorResponse |
| 3866 | errors.As(CheckResponse(res), &err) |
| 3867 | |
| 3868 | if err == nil { |
| 3869 | t.Error("Expected error response.") |
| 3870 | } |
| 3871 | |
| 3872 | want := &ErrorResponse{ |
| 3873 | Response: res, |
| 3874 | Message: "m", |
| 3875 | Errors: []Error{{Message: "error 1"}}, |
| 3876 | } |
| 3877 | if !errors.Is(err, want) { |
| 3878 | t.Errorf("Error = %#v, want %#v", err, want) |
| 3879 | } |
| 3880 | data, err2 := io.ReadAll(err.Response.Body) |
| 3881 | if err2 != nil { |
| 3882 | t.Fatalf("failed to read response body: %v", err) |
| 3883 | } |
| 3884 | if got := string(data); got != httpBody { |
| 3885 | t.Errorf("ErrorResponse.Response.Body = %q, want %q", got, httpBody) |
| 3886 | } |
| 3887 | } |
| 3888 | |
| 3889 | // TestCheckResponse_LargeBodyTruncated verifies that CheckResponse reads at |
| 3890 | // most maxErrorBodySize bytes from an error response body, so that a |
nothing calls this directly
no test coverage detected
searching dependent graphs…