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

Function TestValueBinder_GetValues

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

Source from the content-addressed store, hash-verified

198}
199
200func TestValueBinder_GetValues(t *testing.T) {
201 var testCases = []struct {
202 whenValuesFunc func(sourceParam string) []string
203 name string
204 expectError string
205 expect []int64
206 }{
207 {
208 name: "ok, default implementation",
209 expect: []int64{1, 101},
210 },
211 {
212 name: "ok, values returns nil",
213 whenValuesFunc: func(sourceParam string) []string {
214 return nil
215 },
216 expect: []int64(nil),
217 },
218 {
219 name: "ok, values returns empty slice",
220 whenValuesFunc: func(sourceParam string) []string {
221 return []string{}
222 },
223 expect: []int64(nil),
224 },
225 }
226
227 for _, tc := range testCases {
228 t.Run(tc.name, func(t *testing.T) {
229 c := createTestContext("/search?nr=en&id=1&id=101", nil, nil)
230 b := QueryParamsBinder(c)
231 if tc.whenValuesFunc != nil {
232 b.ValuesFunc = tc.whenValuesFunc
233 }
234
235 var IDs []int64
236 err := b.Int64s("id", &IDs).BindError()
237
238 assert.Equal(t, tc.expect, IDs)
239 if tc.expectError != "" {
240 assert.EqualError(t, err, tc.expectError)
241 } else {
242 assert.NoError(t, err)
243 }
244 })
245 }
246}
247
248func TestValueBinder_CustomFuncWithError(t *testing.T) {
249 c := createTestContext("/search?nr=en&id=1&id=101", nil, nil)

Callers

nothing calls this directly

Calls 4

createTestContextFunction · 0.85
QueryParamsBinderFunction · 0.85
BindErrorMethod · 0.80
Int64sMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…