github.com/u-root/u-root@v7.0.1-0.20200915234505-ad7babab0a8e+incompatible/pkg/dhclient/iface_test.go (about) 1 // Copyright 2019 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 dhclient 6 7 import "testing" 8 9 // TestSimple tests the cases where we should have at least one. 10 func TestInterfaces(t *testing.T) { 11 l, err := Interfaces(".") 12 if err != nil { 13 t.Fatalf("Checking \".\": got %v, want nil", err) 14 } 15 if len(l) == 0 { 16 t.Fatalf("Checking \".\": got no elements, want at least one") 17 } 18 // Grab the first one, wrap it in ^$, and we should only get one back. 19 one := "^" + l[0].Attrs().Name + "$" 20 l, err = Interfaces(one) 21 if err != nil { 22 t.Fatalf("Checking %s: got %v, want nil", one, err) 23 } 24 if len(l) != 1 { 25 t.Errorf("Matching %s: got %d elements(%v), expect 1", one, len(l), l) 26 } 27 }