MCPcopy Create free account
hub / github.com/PerpetualSoftware/pad / errorServer

Function errorServer

internal/cli/item_notfound_test.go:18–29  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

16// the server's writeError shape. Lets us exercise the CLI's error-wrapping
17// without a live backend.
18func 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

Callers 2

TestGetItemWrapsNotFoundFunction · 0.85

Calls 4

EncodeMethod · 0.65
SetMethod · 0.45
HeaderMethod · 0.45
WriteHeaderMethod · 0.45

Tested by

no test coverage detected