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

Function TestStringToTimeDurationHookFunc

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

Source from the content-addressed store, hash-verified

244}
245
246func TestStringToTimeDurationHookFunc(t *testing.T) {
247 f := StringToTimeDurationHookFunc()
248
249 timeValue := reflect.ValueOf(time.Duration(5))
250 strValue := reflect.ValueOf("")
251 cases := []struct {
252 f, t reflect.Value
253 result interface{}
254 err bool
255 }{
256 {reflect.ValueOf("5s"), timeValue, 5 * time.Second, false},
257 {reflect.ValueOf("5"), timeValue, time.Duration(0), true},
258 {reflect.ValueOf("5"), strValue, "5", false},
259 }
260
261 for i, tc := range cases {
262 actual, err := DecodeHookExec(f, tc.f, tc.t)
263 if tc.err != (err != nil) {
264 t.Fatalf("case %d: expected err %#v", i, tc.err)
265 }
266 if !reflect.DeepEqual(actual, tc.result) {
267 t.Fatalf(
268 "case %d: expected %#v, got %#v",
269 i, tc.result, actual)
270 }
271 }
272}
273
274func TestStringToTimeHookFunc(t *testing.T) {
275 strValue := reflect.ValueOf("5")

Callers

nothing calls this directly

Calls 2

DecodeHookExecFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…