(t *testing.T)
| 329 | } |
| 330 | |
| 331 | func TestStringToIPNetHookFunc(t *testing.T) { |
| 332 | strValue := reflect.ValueOf("5") |
| 333 | ipNetValue := reflect.ValueOf(net.IPNet{}) |
| 334 | var nilNet *net.IPNet = nil |
| 335 | |
| 336 | cases := []struct { |
| 337 | f, t reflect.Value |
| 338 | result interface{} |
| 339 | err bool |
| 340 | }{ |
| 341 | {reflect.ValueOf("1.2.3.4/24"), ipNetValue, |
| 342 | &net.IPNet{ |
| 343 | IP: net.IP{0x01, 0x02, 0x03, 0x00}, |
| 344 | Mask: net.IPv4Mask(0xff, 0xff, 0xff, 0x00), |
| 345 | }, false}, |
| 346 | {strValue, ipNetValue, nilNet, true}, |
| 347 | {strValue, strValue, "5", false}, |
| 348 | } |
| 349 | |
| 350 | for i, tc := range cases { |
| 351 | f := StringToIPNetHookFunc() |
| 352 | actual, err := DecodeHookExec(f, tc.f, tc.t) |
| 353 | if tc.err != (err != nil) { |
| 354 | t.Fatalf("case %d: expected err %#v", i, tc.err) |
| 355 | } |
| 356 | if !reflect.DeepEqual(actual, tc.result) { |
| 357 | t.Fatalf( |
| 358 | "case %d: expected %#v, got %#v", |
| 359 | i, tc.result, actual) |
| 360 | } |
| 361 | } |
| 362 | } |
| 363 | |
| 364 | func TestWeaklyTypedHook(t *testing.T) { |
| 365 | var f DecodeHookFunc = WeaklyTypedHook |
nothing calls this directly
no test coverage detected
searching dependent graphs…