Ensure that we properly handle API errors that do not contain a response body.
(t *testing.T)
| 3833 | |
| 3834 | // Ensure that we properly handle API errors that do not contain a response body. |
| 3835 | func TestCheckResponse_noBody(t *testing.T) { |
| 3836 | t.Parallel() |
| 3837 | res := &http.Response{ |
| 3838 | Request: &http.Request{}, |
| 3839 | StatusCode: http.StatusBadRequest, |
| 3840 | Body: io.NopCloser(strings.NewReader("")), |
| 3841 | } |
| 3842 | var err *ErrorResponse |
| 3843 | errors.As(CheckResponse(res), &err) |
| 3844 | |
| 3845 | if err == nil { |
| 3846 | t.Error("Expected error response.") |
| 3847 | } |
| 3848 | |
| 3849 | want := &ErrorResponse{ |
| 3850 | Response: res, |
| 3851 | } |
| 3852 | if !errors.Is(err, want) { |
| 3853 | t.Errorf("Error = %#v, want %#v", err, want) |
| 3854 | } |
| 3855 | } |
| 3856 | |
| 3857 | func TestCheckResponse_unexpectedErrorStructure(t *testing.T) { |
| 3858 | t.Parallel() |
nothing calls this directly
no test coverage detected
searching dependent graphs…