MCPcopy
hub / github.com/gin-gonic/gin / TestMappingTimeDuration

Function TestMappingTimeDuration

binding/form_mapping_test.go:254–282  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

252}
253
254func TestMappingTimeDuration(t *testing.T) {
255 type needFixDurationEmpty struct {
256 Duration time.Duration `form:"duration"`
257 }
258
259 var s struct {
260 D time.Duration
261 }
262
263 // ok
264 err := mappingByPtr(&s, formSource{"D": {"5s"}}, "form")
265 require.NoError(t, err)
266 assert.Equal(t, 5*time.Second, s.D)
267
268 // ok
269 tests := []bindTestData{
270 {need: &needFixDurationEmpty{}, got: &needFixDurationEmpty{}, in: formSource{"duration": []string{" "}}},
271 {need: &needFixDurationEmpty{}, got: &needFixDurationEmpty{}, in: formSource{"duration": []string{}}},
272 }
273
274 for _, v := range tests {
275 err := mapForm(v.got, v.in)
276 require.NoError(t, err)
277 assert.Equal(t, v.need, v.got)
278 }
279 // error
280 err = mappingByPtr(&s, formSource{"D": {"wrong"}}, "form")
281 require.Error(t, err)
282}
283
284func TestMappingSlice(t *testing.T) {
285 var s struct {

Callers

nothing calls this directly

Calls 3

mappingByPtrFunction · 0.85
mapFormFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected