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)
| 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. |
| 23 | func 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. |
no test coverage detected