MCPcopy
hub / github.com/go-playground/validator / TestIPValidation

Function TestIPValidation

validator_test.go:2473–2511  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2471}
2472
2473func TestIPValidation(t *testing.T) {
2474 tests := []struct {
2475 param string
2476 expected bool
2477 }{
2478 {"", false},
2479 {"10.0.0.1", true},
2480 {"172.16.0.1", true},
2481 {"192.168.0.1", true},
2482 {"192.168.255.254", true},
2483 {"192.168.255.256", false},
2484 {"172.16.255.254", true},
2485 {"172.16.256.255", false},
2486 {"2001:cdba:0000:0000:0000:0000:3257:9652", true},
2487 {"2001:cdba:0:0:0:0:3257:9652", true},
2488 {"2001:cdba::3257:9652", true},
2489 }
2490
2491 validate := New()
2492
2493 for i, test := range tests {
2494 errs := validate.Var(test.param, "ip")
2495
2496 if test.expected {
2497 if !IsEqual(errs, nil) {
2498 t.Fatalf("Index: %d ip failed Error: %s", i, errs)
2499 }
2500 } else {
2501 if IsEqual(errs, nil) {
2502 t.Fatalf("Index: %d ip failed Error: %s", i, errs)
2503 } else {
2504 val := getError(errs, "", "")
2505 if val.Tag() != "ip" {
2506 t.Fatalf("Index: %d ip failed Error: %s", i, errs)
2507 }
2508 }
2509 }
2510 }
2511}
2512
2513func TestIPv6Validation(t *testing.T) {
2514 tests := []struct {

Callers

nothing calls this directly

Calls 4

NewFunction · 0.85
getErrorFunction · 0.85
VarMethod · 0.80
TagMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…