validate_test.go (1085B)
1 package netutil 2 3 import ( 4 "net/netip" 5 "testing" 6 ) 7 8 func TestValidateIP(t *testing.T) { 9 tests := []struct { 10 name string 11 ip netip.Addr 12 }{ 13 // IPv4 tests 14 { 15 name: "IPv4 this host on this network", 16 ip: netip.MustParseAddr("0.0.0.0"), 17 }, 18 { 19 name: "IPv4 dummy address", 20 ip: netip.MustParseAddr("192.0.0.8"), 21 }, 22 { 23 name: "IPv4 Port Control Protocol Anycast", 24 ip: netip.MustParseAddr("192.0.0.9"), 25 }, 26 { 27 name: "IPv4 Traversal Using Relays around NAT Anycast", 28 ip: netip.MustParseAddr("192.0.0.10"), 29 }, 30 { 31 name: "IPv4 NAT64/DNS64 Discovery 1", 32 ip: netip.MustParseAddr("192.0.0.17"), 33 }, 34 { 35 name: "IPv4 NAT64/DNS64 Discovery 2", 36 ip: netip.MustParseAddr("192.0.0.171"), 37 }, 38 // IPv6 tests 39 { 40 name: "IPv4-mapped address", 41 ip: netip.MustParseAddr("::ffff:169.254.169.254"), 42 }, 43 } 44 45 for _, tc := range tests { 46 tc := tc 47 t.Run(tc.name, func(t *testing.T) { 48 t.Parallel() 49 if valid := ValidateIP(tc.ip); valid != false { 50 t.Fatalf("Expected IP %s to be: %t, got: %t", tc.ip, false, valid) 51 } 52 }) 53 } 54 }