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

Function fakeSessionServer

internal/cli/bootstrap_test.go:23–35  ·  view source on GitHub ↗

fakeSessionServer returns an httptest.Server whose /api/v1/auth/session handler responds with the SessionResponse produced by `gen` (called once per request so tests can flip setup_required mid-poll). On any other path it 404s — caller is responsible for not hitting other endpoints.

(t *testing.T, gen func() SessionResponse)

Source from the content-addressed store, hash-verified

21// per request so tests can flip setup_required mid-poll). On any other
22// path it 404s — caller is responsible for not hitting other endpoints.
23func fakeSessionServer(t *testing.T, gen func() SessionResponse) *httptest.Server {
24 t.Helper()
25 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
26 if r.URL.Path != "/api/v1/auth/session" {
27 http.Error(w, "not found", http.StatusNotFound)
28 return
29 }
30 w.Header().Set("Content-Type", "application/json")
31 _ = json.NewEncoder(w).Encode(gen())
32 }))
33 t.Cleanup(srv.Close)
34 return srv
35}
36
37// newTestConfig points DataDir at a fresh tmp dir and BrowserURL at the
38// given test server. Most tests want both wired up together.

Calls 4

EncodeMethod · 0.65
ErrorMethod · 0.45
SetMethod · 0.45
HeaderMethod · 0.45

Tested by

no test coverage detected