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

Function TestQueryParamsBinder_FailFast

binder_test.go:90–132  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

88}
89
90func TestQueryParamsBinder_FailFast(t *testing.T) {
91 var testCases = []struct {
92 name string
93 whenURL string
94 expectError []string
95 givenFailFast bool
96 }{
97 {
98 name: "ok, FailFast=true stops at first error",
99 whenURL: "/api/user/999?nr=en&id=nope",
100 givenFailFast: true,
101 expectError: []string{
102 `code=400, message=failed to bind field value to int64, err=strconv.ParseInt: parsing "nope": invalid syntax, field=id`,
103 },
104 },
105 {
106 name: "ok, FailFast=false encounters all errors",
107 whenURL: "/api/user/999?nr=en&id=nope",
108 givenFailFast: false,
109 expectError: []string{
110 `code=400, message=failed to bind field value to int64, err=strconv.ParseInt: parsing "nope": invalid syntax, field=id`,
111 `code=400, message=failed to bind field value to int64, err=strconv.ParseInt: parsing "en": invalid syntax, field=nr`,
112 },
113 },
114 }
115
116 for _, tc := range testCases {
117 t.Run(tc.name, func(t *testing.T) {
118 c := createTestContext(tc.whenURL, nil, map[string]string{"id": "999"})
119 b := QueryParamsBinder(c).FailFast(tc.givenFailFast)
120 id := int64(99)
121 nr := int64(88)
122 errs := b.Int64("id", &id).
123 Int64("nr", &nr).
124 BindErrors()
125
126 assert.Len(t, errs, len(tc.expectError))
127 for _, err := range errs {
128 assert.Contains(t, tc.expectError, err.Error())
129 }
130 })
131 }
132}
133
134func TestFormFieldBinder(t *testing.T) {
135 e := New()

Callers

nothing calls this directly

Calls 6

createTestContextFunction · 0.85
QueryParamsBinderFunction · 0.85
FailFastMethod · 0.80
BindErrorsMethod · 0.80
Int64Method · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…