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>
This commit is contained in:
Josh Bleecher Snyder 2021-11-05 15:34:20 -07:00 committed by Brad Fitzpatrick
parent b07c41d2c1
commit 3b7e376df8

View file

@ -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) {