gopkg.in/hugelgupf/u-root.v9@v9.0.0-20180831063832-3f6f1057f09b/cmds/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  	test   string
    18  	out    string
    19  }{
    20  	{
    21  		iface:  "nosuchanimal",
    22  		isIPv4: "-ipv4=true",
    23  		test:   "-test=true",
    24  		out:    "No interfaces match nosuchanimal\n",
    25  	},
    26  }
    27  
    28  func TestDhclient(t *testing.T) {
    29  	for _, tt := range tests {
    30  		out, err := testutil.Command(t, tt.isIPv4, tt.test, tt.iface).CombinedOutput()
    31  		if err == nil {
    32  			t.Errorf("%v: got nil, want err", tt)
    33  		}
    34  		if !strings.HasSuffix(string(out), tt.out) {
    35  			t.Errorf("expected:\n%s\ngot:\n%s", tt.out, string(out))
    36  		}
    37  	}
    38  }
    39  
    40  func TestMain(m *testing.M) {
    41  	testutil.Run(m, main)
    42  }