diff options
author | Josh Bleecher Snyder <josharian@gmail.com> | 2021-11-05 15:34:20 -0700 |
---|---|---|
committer | Brad Fitzpatrick <bradfitz@golang.org> | 2021-11-05 22:53:55 +0000 |
commit | 3b7e376df87fa5255c7aa58d5719593b314338fd (patch) | |
tree | e5edc76877aba10293e39e9990b071926cd08277 /src/net | |
parent | b07c41d2c1c8d5729250a13b7c560c150c1d9011 (diff) | |
download | go-3b7e376df87fa5255c7aa58d5719593b314338fd.tar.gz go-3b7e376df87fa5255c7aa58d5719593b314338fd.zip |
net/netip: add tests for Addr.AsSlice
Change-Id: Ib88dd101b3bbdf4d2bfd79838994cfadef1b604d
Reviewed-on: https://go-review.googlesource.com/c/go/+/361915
Trust: Josh Bleecher Snyder <josharian@gmail.com>
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Diffstat (limited to 'src/net')
-rw-r--r-- | src/net/netip/netip_test.go | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/net/netip/netip_test.go b/src/net/netip/netip_test.go index 63af853cb3..a6327f0dea 100644 --- a/src/net/netip/netip_test.go +++ b/src/net/netip/netip_test.go @@ -1889,6 +1889,24 @@ func TestInvalidAddrPortString(t *testing.T) { } } +func TestAsSlice(t *testing.T) { + tests := []struct { + in Addr + want []byte + }{ + {in: Addr{}, want: nil}, + {in: mustIP("1.2.3.4"), want: []byte{1, 2, 3, 4}}, + {in: mustIP("ffff::1"), want: []byte{0xff, 0xff, 15: 1}}, + } + + for _, test := range tests { + got := test.in.AsSlice() + if !bytes.Equal(got, test.want) { + t.Errorf("%v.AsSlice() = %v want %v", test.in, got, test.want) + } + } +} + var sink16 [16]byte func BenchmarkAs16(b *testing.B) { |