(t *testing.T)
| 301 | } |
| 302 | |
| 303 | func TestStringToIPHookFunc(t *testing.T) { |
| 304 | strValue := reflect.ValueOf("5") |
| 305 | ipValue := reflect.ValueOf(net.IP{}) |
| 306 | cases := []struct { |
| 307 | f, t reflect.Value |
| 308 | result interface{} |
| 309 | err bool |
| 310 | }{ |
| 311 | {reflect.ValueOf("1.2.3.4"), ipValue, |
| 312 | net.IPv4(0x01, 0x02, 0x03, 0x04), false}, |
| 313 | {strValue, ipValue, net.IP{}, true}, |
| 314 | {strValue, strValue, "5", false}, |
| 315 | } |
| 316 | |
| 317 | for i, tc := range cases { |
| 318 | f := StringToIPHookFunc() |
| 319 | actual, err := DecodeHookExec(f, tc.f, tc.t) |
| 320 | if tc.err != (err != nil) { |
| 321 | t.Fatalf("case %d: expected err %#v", i, tc.err) |
| 322 | } |
| 323 | if !reflect.DeepEqual(actual, tc.result) { |
| 324 | t.Fatalf( |
| 325 | "case %d: expected %#v, got %#v", |
| 326 | i, tc.result, actual) |
| 327 | } |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | func TestStringToIPNetHookFunc(t *testing.T) { |
| 332 | strValue := reflect.ValueOf("5") |
nothing calls this directly
no test coverage detected
searching dependent graphs…