(t *testing.T)
| 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"}) |
| 356 | |
| 357 | var out, errOut bytes.Buffer |
| 358 | err := HandleResponse(resp, ResponseOptions{Out: &out, ErrOut: &errOut, FileIO: &localfileio.LocalFileIO{}}) |
| 359 | if err == nil { |
| 360 | t.Fatal("expected error for 502 text/html") |
| 361 | } |
| 362 | got := err.Error() |
| 363 | if !strings.Contains(got, "HTTP 502") || !strings.Contains(got, "Bad Gateway") { |
| 364 | t.Errorf("expected 'HTTP 502' and 'Bad Gateway' in error, got: %s", got) |
| 365 | } |
| 366 | var netErr *errs.NetworkError |
| 367 | if !errors.As(err, &netErr) { |
| 368 | t.Errorf("expected *errs.NetworkError, got %T", err) |
| 369 | } |
| 370 | if output.ExitCodeOf(err) != output.ExitNetwork { |
| 371 | t.Errorf("expected ExitNetwork (%d) for 5xx, got %d", output.ExitNetwork, output.ExitCodeOf(err)) |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | // TestHandleResponse_JSONErrorWithZeroBodyCodeNotSwallowed pins that an HTTP |
| 376 | // status error whose JSON body omits a non-zero business code (e.g. 400 + |
nothing calls this directly
no test coverage detected