MCPcopy
hub / github.com/labstack/echo / TestPathParam

Function TestPathParam

binder_generic_test.go:43–87  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

41}
42
43func TestPathParam(t *testing.T) {
44 var testCases = []struct {
45 name string
46 givenKey string
47 givenValue string
48 expect bool
49 expectErr string
50 }{
51 {
52 name: "ok",
53 givenValue: "true",
54 expect: true,
55 },
56 {
57 name: "nok, non existent key",
58 givenKey: "missing",
59 givenValue: "true",
60 expect: false,
61 expectErr: ErrNonExistentKey.Error(),
62 },
63 {
64 name: "nok, invalid value",
65 givenValue: "can_parse_me",
66 expect: false,
67 expectErr: `code=400, message=path value, err=failed to parse value, err: strconv.ParseBool: parsing "can_parse_me": invalid syntax, field=key`,
68 },
69 }
70 for _, tc := range testCases {
71 t.Run(tc.name, func(t *testing.T) {
72 c := NewContext(nil, nil)
73 c.SetPathValues(PathValues{{
74 Name: cmp.Or(tc.givenKey, "key"),
75 Value: tc.givenValue,
76 }})
77
78 v, err := PathParam[bool](c, "key")
79 if tc.expectErr != "" {
80 assert.EqualError(t, err, tc.expectErr)
81 } else {
82 assert.NoError(t, err)
83 }
84 assert.Equal(t, tc.expect, v)
85 })
86 }
87}
88
89func TestPathParam_UnsupportedType(t *testing.T) {
90 c := NewContext(nil, nil)

Callers

nothing calls this directly

Calls 3

SetPathValuesMethod · 0.95
NewContextFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…