MCPcopy Index your code
hub / github.com/labstack/echo / TestCreateExtractors

Function TestCreateExtractors

middleware/extractor_test.go:20–127  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

18)
19
20func TestCreateExtractors(t *testing.T) {
21 var testCases = []struct {
22 name string
23 givenRequest func() *http.Request
24 givenPathValues echo.PathValues
25 whenLookups string
26 whenLimit uint
27 expectValues []string
28 expectSource ExtractorSource
29 expectCreateError string
30 expectError string
31 }{
32 {
33 name: "ok, header",
34 givenRequest: func() *http.Request {
35 req := httptest.NewRequest(http.MethodGet, "/", nil)
36 req.Header.Set(echo.HeaderAuthorization, "Bearer token")
37 return req
38 },
39 whenLookups: "header:Authorization:Bearer ",
40 expectValues: []string{"token"},
41 expectSource: ExtractorSourceHeader,
42 },
43 {
44 name: "ok, form",
45 givenRequest: func() *http.Request {
46 f := make(url.Values)
47 f.Set("name", "Jon Snow")
48
49 req := httptest.NewRequest(http.MethodPost, "/", strings.NewReader(f.Encode()))
50 req.Header.Add(echo.HeaderContentType, echo.MIMEApplicationForm)
51 return req
52 },
53 whenLookups: "form:name",
54 expectValues: []string{"Jon Snow"},
55 expectSource: ExtractorSourceForm,
56 },
57 {
58 name: "ok, cookie",
59 givenRequest: func() *http.Request {
60 req := httptest.NewRequest(http.MethodGet, "/", nil)
61 req.Header.Set(echo.HeaderCookie, "_csrf=token")
62 return req
63 },
64 whenLookups: "cookie:_csrf",
65 expectValues: []string{"token"},
66 expectSource: ExtractorSourceCookie,
67 },
68 {
69 name: "ok, param",
70 givenPathValues: echo.PathValues{
71 {Name: "id", Value: "123"},
72 },
73 whenLookups: "param:id",
74 expectValues: []string{"123"},
75 expectSource: ExtractorSourcePathParam,
76 },
77 {

Callers

nothing calls this directly

Calls 5

SetPathValuesMethod · 0.95
CreateExtractorsFunction · 0.85
SetMethod · 0.80
NewContextMethod · 0.80
AddMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…