github.com/ratrocket/u-root@v0.0.0-20180201221235-1cf9f48ee2cf/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 "os" 9 "os/exec" 10 "strings" 11 "testing" 12 13 "github.com/u-root/u-root/pkg/testutil" 14 ) 15 16 var tests = []struct { 17 iface string 18 isIPv4 string 19 test string 20 out string 21 }{ 22 { 23 iface: "nosuchanimal", 24 isIPv4: "-ipv4=true", 25 test: "-test=true", 26 out: "No interfaces match nosuchanimal\n", 27 }, 28 } 29 30 func TestDhclient(t *testing.T) { 31 tmpDir, execPath := testutil.CompileInTempDir(t) 32 defer os.RemoveAll(tmpDir) 33 34 for _, tt := range tests { 35 out, err := exec.Command(execPath, tt.isIPv4, tt.test, tt.iface).CombinedOutput() 36 if err == nil { 37 t.Errorf("%v: got nil, want err", tt) 38 } 39 if !strings.HasSuffix(string(out), tt.out) { 40 t.Errorf("expected:\n%s\ngot:\n%s", tt.out, string(out)) 41 } 42 } 43 }