gitlab.com/apertussolutions/u-root@v7.0.0+incompatible/cmds/core/dhclient/dhclient_test.go (about)

     1  // Copyright 2017 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 main
     6  
     7  import (
     8  	"strings"
     9  	"testing"
    10  
    11  	"github.com/u-root/u-root/pkg/testutil"
    12  )
    13  
    14  var tests = []struct {
    15  	iface  string
    16  	isIPv4 string
    17  	out    string
    18  }{
    19  	{
    20  		iface:  "nosuchanimal",
    21  		isIPv4: "-ipv4=true",
    22  		out:    "no interfaces match nosuchanimal\n",
    23  	},
    24  }
    25  
    26  func TestDhclient(t *testing.T) {
    27  	for _, tt := range tests {
    28  		out, err := testutil.Command(t, tt.isIPv4, tt.iface).CombinedOutput()
    29  		if err == nil {
    30  			t.Errorf("%v: got nil, want err", tt)
    31  		}
    32  		if !strings.HasSuffix(string(out), tt.out) {
    33  			t.Errorf("expected:\n%s\ngot:\n%s", tt.out, string(out))
    34  		}
    35  	}
    36  }
    37  
    38  func TestMain(m *testing.M) {
    39  	testutil.Run(m, main)
    40  }