blob: dd0885ae6bbdf6fc09bc6918fbbabfe306c33c48 [file] [log] [blame]
Cosmos Nicolaouf7a11d92014-08-29 09:56:07 -07001package netstate
David Why Use Two When One Will Do Presotto748a0d52014-07-30 17:07:04 -07002
3import (
4 "net"
5 "testing"
6)
7
8func TestIsGloballyRoutable(t *testing.T) {
9 tests := []struct {
10 ip string
11 want bool
12 }{
13 {"192.168.1.1", false},
14 {"192.169.0.3", true},
15 {"10.1.1.1", false},
16 {"172.17.100.255", false},
17 {"172.32.0.1", true},
18 {"255.255.255.255", false},
19 {"127.0.0.1", false},
20 {"224.0.0.1", false},
21 {"FF02::FB", false},
22 {"fe80::be30:5bff:fed3:843f", false},
23 {"2620:0:1000:8400:be30:5bff:fed3:843f", true},
24 }
25 for _, test := range tests {
26 ip := net.ParseIP(test.ip)
Cosmos Nicolaouf7a11d92014-08-29 09:56:07 -070027 if got := IsGloballyRoutableIP(ip); got != test.want {
David Why Use Two When One Will Do Presotto748a0d52014-07-30 17:07:04 -070028 t.Fatalf("%s: want %v got %v", test.ip, test.want, got)
29 }
30 }
31}