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

Function TestValueBinder_DurationError

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

Source from the content-addressed store, hash-verified

3145}
3146
3147func TestValueBinder_DurationError(t *testing.T) {
3148 var testCases = []struct {
3149 name string
3150 whenURL string
3151 expectError string
3152 givenBindErrors []error
3153 expectValue time.Duration
3154 givenFailFast bool
3155 whenMust bool
3156 }{
3157 {
3158 name: "nok, conversion fails, value is not changed",
3159 whenURL: "/search?param=nope&param=100",
3160 expectValue: 0,
3161 expectError: "code=400, message=failed to bind field value to Duration, err=time: invalid duration \"nope\", field=param",
3162 },
3163 {
3164 name: "nok (must), conversion fails, value is not changed",
3165 whenMust: true,
3166 whenURL: "/search?param=nope&param=100",
3167 expectValue: 0,
3168 expectError: "code=400, message=failed to bind field value to Duration, err=time: invalid duration \"nope\", field=param",
3169 },
3170 }
3171
3172 for _, tc := range testCases {
3173 t.Run(tc.name, func(t *testing.T) {
3174 c := createTestContext(tc.whenURL, nil, nil)
3175 b := QueryParamsBinder(c).FailFast(tc.givenFailFast)
3176 if tc.givenFailFast {
3177 b.errors = []error{errors.New("previous error")}
3178 }
3179
3180 var dest time.Duration
3181 var err error
3182 if tc.whenMust {
3183 err = b.MustDuration("param", &dest).BindError()
3184 } else {
3185 err = b.Duration("param", &dest).BindError()
3186 }
3187
3188 assert.Equal(t, tc.expectValue, dest)
3189 if tc.expectError != "" {
3190 assert.EqualError(t, err, tc.expectError)
3191 } else {
3192 assert.NoError(t, err)
3193 }
3194 })
3195 }
3196}
3197
3198func TestValueBinder_DurationsError(t *testing.T) {
3199 var testCases = []struct {

Callers

nothing calls this directly

Calls 6

createTestContextFunction · 0.85
QueryParamsBinderFunction · 0.85
FailFastMethod · 0.80
BindErrorMethod · 0.80
MustDurationMethod · 0.80
DurationMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…