github.com/lianghucheng/zrddz@v0.0.0-20200923083010-c71f680932e2/src/golang.org/x/net/ipv6/header_test.go (about)

     1  // Copyright 2014 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package ipv6_test
     6  
     7  import (
     8  	"net"
     9  	"reflect"
    10  	"strings"
    11  	"testing"
    12  
    13  	"golang.org/x/net/internal/iana"
    14  	"golang.org/x/net/ipv6"
    15  )
    16  
    17  var (
    18  	wireHeaderFromKernel = [ipv6.HeaderLen]byte{
    19  		0x69, 0x8b, 0xee, 0xf1,
    20  		0xca, 0xfe, 0x2c, 0x01,
    21  		0x20, 0x01, 0x0d, 0xb8,
    22  		0x00, 0x01, 0x00, 0x00,
    23  		0x00, 0x00, 0x00, 0x00,
    24  		0x00, 0x00, 0x00, 0x01,
    25  		0x20, 0x01, 0x0d, 0xb8,
    26  		0x00, 0x02, 0x00, 0x00,
    27  		0x00, 0x00, 0x00, 0x00,
    28  		0x00, 0x00, 0x00, 0x01,
    29  	}
    30  
    31  	testHeader = &ipv6.Header{
    32  		Version:      ipv6.Version,
    33  		TrafficClass: iana.DiffServAF43,
    34  		FlowLabel:    0xbeef1,
    35  		PayloadLen:   0xcafe,
    36  		NextHeader:   iana.ProtocolIPv6Frag,
    37  		HopLimit:     1,
    38  		Src:          net.ParseIP("2001:db8:1::1"),
    39  		Dst:          net.ParseIP("2001:db8:2::1"),
    40  	}
    41  )
    42  
    43  func TestParseHeader(t *testing.T) {
    44  	h, err := ipv6.ParseHeader(wireHeaderFromKernel[:])
    45  	if err != nil {
    46  		t.Fatal(err)
    47  	}
    48  	if !reflect.DeepEqual(h, testHeader) {
    49  		t.Fatalf("got %#v; want %#v", h, testHeader)
    50  	}
    51  	s := h.String()
    52  	if strings.Contains(s, ",") {
    53  		t.Fatalf("should be space-separated values: %s", s)
    54  	}
    55  }