github.com/polevpn/netstack@v1.10.9/tcpip/header/eth_test.go (about)

     1  // Copyright 2018 The gVisor Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package header
    16  
    17  import (
    18  	"testing"
    19  
    20  	"github.com/polevpn/netstack/tcpip"
    21  )
    22  
    23  func TestIsValidUnicastEthernetAddress(t *testing.T) {
    24  	tests := []struct {
    25  		name     string
    26  		addr     tcpip.LinkAddress
    27  		expected bool
    28  	}{
    29  		{
    30  			"Nil",
    31  			tcpip.LinkAddress([]byte(nil)),
    32  			false,
    33  		},
    34  		{
    35  			"Empty",
    36  			tcpip.LinkAddress(""),
    37  			false,
    38  		},
    39  		{
    40  			"InvalidLength",
    41  			tcpip.LinkAddress("\x01\x02\x03"),
    42  			false,
    43  		},
    44  		{
    45  			"Unspecified",
    46  			unspecifiedEthernetAddress,
    47  			false,
    48  		},
    49  		{
    50  			"Multicast",
    51  			tcpip.LinkAddress("\x01\x02\x03\x04\x05\x06"),
    52  			false,
    53  		},
    54  		{
    55  			"Valid",
    56  			tcpip.LinkAddress("\x02\x02\x03\x04\x05\x06"),
    57  			true,
    58  		},
    59  	}
    60  
    61  	for _, test := range tests {
    62  		t.Run(test.name, func(t *testing.T) {
    63  			if got := IsValidUnicastEthernetAddress(test.addr); got != test.expected {
    64  				t.Fatalf("got IsValidUnicastEthernetAddress = %t, want = %t", got, test.expected)
    65  			}
    66  		})
    67  	}
    68  }