errorServer returns an httptest.Server that answers every request with the given status + API error envelope ({"error":{"code","message"}}), matching the server's writeError shape. Lets us exercise the CLI's error-wrapping without a live backend.
(t *testing.T, status int, code, message string)
| 16 | // the server's writeError shape. Lets us exercise the CLI's error-wrapping |
| 17 | // without a live backend. |
| 18 | func errorServer(t *testing.T, status int, code, message string) *httptest.Server { |
| 19 | t.Helper() |
| 20 | srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 21 | w.Header().Set("Content-Type", "application/json") |
| 22 | w.WriteHeader(status) |
| 23 | _ = json.NewEncoder(w).Encode(map[string]any{ |
| 24 | "error": map[string]string{"code": code, "message": message}, |
| 25 | }) |
| 26 | })) |
| 27 | t.Cleanup(srv.Close) |
| 28 | return srv |
| 29 | } |
| 30 | |
| 31 | // TestGetItemWrapsNotFound verifies TASK-2031b: a bare "not_found" APIError |
| 32 | // from the item-by-ref endpoint is rewritten to echo the failing ref and |
no test coverage detected