(t *testing.T)
| 244 | } |
| 245 | |
| 246 | func 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 | |
| 274 | func TestStringToTimeHookFunc(t *testing.T) { |
| 275 | strValue := reflect.ValueOf("5") |
nothing calls this directly
no test coverage detected
searching dependent graphs…