(t *testing.T)
| 331 | } |
| 332 | |
| 333 | func TestHandleResponse_NonJSONError_404(t *testing.T) { |
| 334 | resp := newApiRespWithStatus(404, []byte("404 page not found"), map[string]string{"Content-Type": "text/plain"}) |
| 335 | |
| 336 | var out, errOut bytes.Buffer |
| 337 | err := HandleResponse(resp, ResponseOptions{Out: &out, ErrOut: &errOut, FileIO: &localfileio.LocalFileIO{}}) |
| 338 | if err == nil { |
| 339 | t.Fatal("expected error for 404 text/plain") |
| 340 | } |
| 341 | got := err.Error() |
| 342 | if !strings.Contains(got, "HTTP 404") || !strings.Contains(got, "404 page not found") { |
| 343 | t.Errorf("expected 'HTTP 404: 404 page not found', got: %s", got) |
| 344 | } |
| 345 | var apiErr *errs.APIError |
| 346 | if !errors.As(err, &apiErr) { |
| 347 | t.Errorf("expected *errs.APIError, got %T", err) |
| 348 | } |
| 349 | if output.ExitCodeOf(err) != output.ExitAPI { |
| 350 | t.Errorf("expected ExitAPI (%d), got %d", output.ExitAPI, output.ExitCodeOf(err)) |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | func TestHandleResponse_NonJSONError_502(t *testing.T) { |
| 355 | resp := newApiRespWithStatus(502, []byte("<html>Bad Gateway</html>"), map[string]string{"Content-Type": "text/html"}) |
nothing calls this directly
no test coverage detected