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

Function TestValueBinder_DurationsError

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

Source from the content-addressed store, hash-verified

3196}
3197
3198func TestValueBinder_DurationsError(t *testing.T) {
3199 var testCases = []struct {
3200 name string
3201 whenURL string
3202 expectError string
3203 givenBindErrors []error
3204 expectValue []time.Duration
3205 givenFailFast bool
3206 whenMust bool
3207 }{
3208 {
3209 name: "nok, fail fast without binding value",
3210 givenFailFast: true,
3211 whenURL: "/search?param=1&param=100",
3212 expectValue: []time.Duration(nil),
3213 expectError: "code=400, message=failed to bind field value to Duration, err=time: missing unit in duration \"1\", field=param",
3214 },
3215 {
3216 name: "nok, conversion fails, value is not changed",
3217 whenURL: "/search?param=nope&param=100",
3218 expectValue: []time.Duration(nil),
3219 expectError: "code=400, message=failed to bind field value to Duration, err=time: invalid duration \"nope\", field=param",
3220 },
3221 {
3222 name: "nok (must), conversion fails, value is not changed",
3223 whenMust: true,
3224 whenURL: "/search?param=nope&param=100",
3225 expectValue: []time.Duration(nil),
3226 expectError: "code=400, message=failed to bind field value to Duration, err=time: invalid duration \"nope\", field=param",
3227 },
3228 }
3229
3230 for _, tc := range testCases {
3231 t.Run(tc.name, func(t *testing.T) {
3232 c := createTestContext(tc.whenURL, nil, nil)
3233 b := QueryParamsBinder(c).FailFast(tc.givenFailFast)
3234 b.errors = tc.givenBindErrors
3235
3236 var dest []time.Duration
3237 var err error
3238 if tc.whenMust {
3239 err = b.MustDurations("param", &dest).BindError()
3240 } else {
3241 err = b.Durations("param", &dest).BindError()
3242 }
3243
3244 assert.Equal(t, tc.expectValue, dest)
3245 if tc.expectError != "" {
3246 assert.EqualError(t, err, tc.expectError)
3247 } else {
3248 assert.NoError(t, err)
3249 }
3250 })
3251 }
3252}

Callers

nothing calls this directly

Calls 6

createTestContextFunction · 0.85
QueryParamsBinderFunction · 0.85
FailFastMethod · 0.80
BindErrorMethod · 0.80
MustDurationsMethod · 0.80
DurationsMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…