MCPcopy
hub / github.com/gofiber/fiber / Test_Extractors_Missing

Function Test_Extractors_Missing

extractors/extractors_test.go:15–56  ·  view source on GitHub ↗

go test -run Test_Extractors_Missing

(t *testing.T)

Source from the content-addressed store, hash-verified

13
14// go test -run Test_Extractors_Missing
15func Test_Extractors_Missing(t *testing.T) {
16 t.Parallel()
17
18 app := fiber.New()
19 // Add a route to test the missing param
20 app.Get("/test", func(c fiber.Ctx) error {
21 token, err := FromParam("token").Extract(c)
22 require.Empty(t, token)
23 require.ErrorIs(t, err, ErrNotFound)
24 return nil
25 })
26 _, err := app.Test(newRequest("/test"))
27 require.NoError(t, err)
28
29 ctx := app.AcquireCtx(&fasthttp.RequestCtx{})
30 t.Cleanup(func() { app.ReleaseCtx(ctx) })
31
32 // Missing form
33 token, err := FromForm("token").Extract(ctx)
34 require.Empty(t, token)
35 require.ErrorIs(t, err, ErrNotFound)
36
37 // Missing query
38 token, err = FromQuery("token").Extract(ctx)
39 require.Empty(t, token)
40 require.ErrorIs(t, err, ErrNotFound)
41
42 // Missing header
43 token, err = FromHeader("X-Token").Extract(ctx)
44 require.Empty(t, token)
45 require.ErrorIs(t, err, ErrNotFound)
46
47 // Missing Auth header
48 token, err = FromAuthHeader("Bearer").Extract(ctx)
49 require.Empty(t, token)
50 require.ErrorIs(t, err, ErrNotFound)
51
52 // Missing cookie
53 token, err = FromCookie("token").Extract(ctx)
54 require.Empty(t, token)
55 require.ErrorIs(t, err, ErrNotFound)
56}
57
58// newRequest creates a new GET *http.Request for Fiber's app.Test.
59func newRequest(target string) *http.Request {

Callers

nothing calls this directly

Calls 12

FromParamFunction · 0.85
newRequestFunction · 0.85
FromFormFunction · 0.85
FromQueryFunction · 0.85
FromHeaderFunction · 0.85
FromAuthHeaderFunction · 0.85
FromCookieFunction · 0.85
TestMethod · 0.80
AcquireCtxMethod · 0.80
ReleaseCtxMethod · 0.80
NewMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected