diff options
author | Tamir Duberstein <tamird@google.com> | 2018-09-21 13:57:24 -0700 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2018-09-21 13:58:31 -0700 |
commit | 4634cd66ad036023c218dd6c3899194039cc608b (patch) | |
tree | dc3a9bbb36ad5fd9160f74aa58770b59f10627a7 /pkg/tcpip/tcpip_test.go | |
parent | d260e808f478e5c5b96d574d49f315f3823aa385 (diff) |
Extend tcpip.Address.String to ipv6 addresses
PiperOrigin-RevId: 214039349
Change-Id: Ia7d09c5f85eddd1e5634f3c21b0bd60b10be6bd2
Diffstat (limited to 'pkg/tcpip/tcpip_test.go')
-rw-r--r-- | pkg/tcpip/tcpip_test.go | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/pkg/tcpip/tcpip_test.go b/pkg/tcpip/tcpip_test.go index 6bf82d632..9b20c74c6 100644 --- a/pkg/tcpip/tcpip_test.go +++ b/pkg/tcpip/tcpip_test.go @@ -15,6 +15,7 @@ package tcpip import ( + "net" "testing" ) @@ -138,3 +139,57 @@ func TestRouteMatch(t *testing.T) { } } } + +func TestAddressString(t *testing.T) { + for _, want := range []string{ + // Taken from stdlib. + "2001:db8::123:12:1", + "2001:db8::1", + "2001:db8:0:1:0:1:0:1", + "2001:db8:1:0:1:0:1:0", + "2001::1:0:0:1", + "2001:db8:0:0:1::", + "2001:db8::1:0:0:1", + "2001:db8::a:b:c:d", + + // Leading zeros. + "::1", + // Trailing zeros. + "8::", + // No zeros. + "1:1:1:1:1:1:1:1", + // Longer sequence is after other zeros, but not at the end. + "1:0:0:1::1", + // Longer sequence is at the beginning, shorter sequence is at + // the end. + "::1:1:1:0:0", + // Longer sequence is not at the beginning, shorter sequence is + // at the end. + "1::1:1:0:0", + // Longer sequence is at the beginning, shorter sequence is not + // at the end. + "::1:1:0:0:1", + // Neither sequence is at an end, longer is after shorter. + "1:0:0:1::1", + // Shorter sequence is at the beginning, longer sequence is not + // at the end. + "0:0:1:1::1", + // Shorter sequence is at the beginning, longer sequence is at + // the end. + "0:0:1:1:1::", + // Short sequences at both ends, longer one in the middle. + "0:1:1::1:1:0", + // Short sequences at both ends, longer one in the middle. + "0:1::1:0:0", + // Short sequences at both ends, longer one in the middle. + "0:0:1::1:0", + // Longer sequence surrounded by shorter sequences, but none at + // the end. + "1:0:1::1:0:1", + } { + addr := Address(net.ParseIP(want)) + if got := addr.String(); got != want { + t.Errorf("Address(%x).String() = '%s', want = '%s'", addr, got, want) + } + } +} |