TestChat401: maps to typed ErrUnauthorized.
(t *testing.T)
| 444 | |
| 445 | // TestChat401: maps to typed ErrUnauthorized. |
| 446 | func TestChat401(t *testing.T) { |
| 447 | srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { |
| 448 | w.WriteHeader(http.StatusUnauthorized) |
| 449 | })) |
| 450 | defer srv.Close() |
| 451 | evs := collect(New(srv.URL, "m", "").Chat(context.Background(), nil, nil)) |
| 452 | if len(evs) != 1 || !errors.Is(evs[0].Err, cloud.ErrUnauthorized) { |
| 453 | t.Fatalf("want ErrUnauthorized, got %+v", evs) |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | // TestChat401DrainsBodyForConnReuse: a 401 carrying a body must have that body |
| 458 | // drained before close, or Go's transport discards the TCP connection instead |