github.com/mvdan/u-root-coreutils@v0.0.0-20230122170626-c2eef2898555/pkg/boot/netboot/pxe/pxe_test.go (about)

     1  // Copyright 2017-2018 the u-root 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 pxe
     6  
     7  import (
     8  	"net"
     9  	"reflect"
    10  	"testing"
    11  )
    12  
    13  func TestProbeFiles(t *testing.T) {
    14  	// Anyone got some ideas for other test cases?
    15  	for _, tt := range []struct {
    16  		mac   net.HardwareAddr
    17  		ip    net.IP
    18  		files []string
    19  	}{
    20  		{
    21  			mac: []byte{0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff},
    22  			ip:  []byte{192, 168, 0, 1},
    23  			files: []string{
    24  				"01-aa-bb-cc-dd-ee-ff",
    25  				"C0A80001",
    26  				"C0A8000",
    27  				"C0A800",
    28  				"C0A80",
    29  				"C0A8",
    30  				"C0A",
    31  				"C0",
    32  				"C",
    33  				"default",
    34  			},
    35  		},
    36  		{
    37  			mac: []byte{0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd},
    38  			ip:  []byte{192, 168, 2, 91},
    39  			files: []string{
    40  				"01-88-99-aa-bb-cc-dd",
    41  				"C0A8025B",
    42  				"C0A8025",
    43  				"C0A802",
    44  				"C0A80",
    45  				"C0A8",
    46  				"C0A",
    47  				"C0",
    48  				"C",
    49  				"default",
    50  			},
    51  		},
    52  	} {
    53  		got := probeFiles(tt.mac, tt.ip)
    54  		if !reflect.DeepEqual(got, tt.files) {
    55  			t.Errorf("probeFiles(%s, %s) = %v, want %v", tt.mac, tt.ip, got, tt.files)
    56  		}
    57  	}
    58  }