MCPcopy
hub / github.com/mitchellh/mapstructure / TestStringToTimeHookFunc

Function TestStringToTimeHookFunc

decode_hooks_test.go:274–301  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

272}
273
274func TestStringToTimeHookFunc(t *testing.T) {
275 strValue := reflect.ValueOf("5")
276 timeValue := reflect.ValueOf(time.Time{})
277 cases := []struct {
278 f, t reflect.Value
279 layout string
280 result interface{}
281 err bool
282 }{
283 {reflect.ValueOf("2006-01-02T15:04:05Z"), timeValue, time.RFC3339,
284 time.Date(2006, 1, 2, 15, 4, 5, 0, time.UTC), false},
285 {strValue, timeValue, time.RFC3339, time.Time{}, true},
286 {strValue, strValue, time.RFC3339, "5", false},
287 }
288
289 for i, tc := range cases {
290 f := StringToTimeHookFunc(tc.layout)
291 actual, err := DecodeHookExec(f, tc.f, tc.t)
292 if tc.err != (err != nil) {
293 t.Fatalf("case %d: expected err %#v", i, tc.err)
294 }
295 if !reflect.DeepEqual(actual, tc.result) {
296 t.Fatalf(
297 "case %d: expected %#v, got %#v",
298 i, tc.result, actual)
299 }
300 }
301}
302
303func TestStringToIPHookFunc(t *testing.T) {
304 strValue := reflect.ValueOf("5")

Callers

nothing calls this directly

Calls 2

StringToTimeHookFuncFunction · 0.85
DecodeHookExecFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…