mirror of
https://github.com/golang/go
synced 2024-11-05 18:36:08 +00:00
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:
parent
b07c41d2c1
commit
3b7e376df8
1 changed files with 18 additions and 0 deletions
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue