(t *testing.T)
| 252 | } |
| 253 | |
| 254 | func 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 | |
| 284 | func TestMappingSlice(t *testing.T) { |
| 285 | var s struct { |
nothing calls this directly
no test coverage detected