]> Cypherpunks repositories - gostls13.git/commitdiff
net/netip: add tests for Addr.AsSlice
authorJosh Bleecher Snyder <josharian@gmail.com>
Fri, 5 Nov 2021 22:34:20 +0000 (15:34 -0700)
committerBrad Fitzpatrick <bradfitz@golang.org>
Fri, 5 Nov 2021 22:53:55 +0000 (22:53 +0000)
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>

src/net/netip/netip_test.go

index 63af853cb3e103b25be4bd60ba348910d8f2bc03..a6327f0dea826fd7d6035ddfb94da7139959d124 100644 (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) {