nolint:bodyclose
(t *testing.T)
| 15 | |
| 16 | //nolint:bodyclose |
| 17 | func TestExternalAuthParam(t *testing.T) { |
| 18 | t.Parallel() |
| 19 | t.Run("Found", func(t *testing.T) { |
| 20 | t.Parallel() |
| 21 | routeCtx := chi.NewRouteContext() |
| 22 | routeCtx.URLParams.Add("externalauth", "my-id") |
| 23 | r := httptest.NewRequest(http.MethodGet, "/", nil) |
| 24 | r = r.WithContext(context.WithValue(r.Context(), chi.RouteCtxKey, routeCtx)) |
| 25 | res := httptest.NewRecorder() |
| 26 | |
| 27 | httpmw.ExtractExternalAuthParam([]*externalauth.Config{{ |
| 28 | ID: "my-id", |
| 29 | }})(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 30 | require.Equal(t, "my-id", httpmw.ExternalAuthParam(r).ID) |
| 31 | w.WriteHeader(http.StatusOK) |
| 32 | })).ServeHTTP(res, r) |
| 33 | |
| 34 | require.Equal(t, http.StatusOK, res.Result().StatusCode) |
| 35 | }) |
| 36 | |
| 37 | t.Run("NotFound", func(t *testing.T) { |
| 38 | t.Parallel() |
| 39 | routeCtx := chi.NewRouteContext() |
| 40 | routeCtx.URLParams.Add("externalauth", "my-id") |
| 41 | r := httptest.NewRequest(http.MethodGet, "/", nil) |
| 42 | r = r.WithContext(context.WithValue(r.Context(), chi.RouteCtxKey, routeCtx)) |
| 43 | res := httptest.NewRecorder() |
| 44 | |
| 45 | httpmw.ExtractExternalAuthParam([]*externalauth.Config{})(nil).ServeHTTP(res, r) |
| 46 | |
| 47 | require.Equal(t, http.StatusNotFound, res.Result().StatusCode) |
| 48 | }) |
| 49 | } |
nothing calls this directly
no test coverage detected