net: adjust TestInterfaceHardwareAddrWithGetmac

CL skips interfaces that are not listed on getmac output.

Fixes #13606

Change-Id: Ic25c9dc95e8eeff4d84b78e99131a4f97020164c
Reviewed-on: https://go-review.googlesource.com/17994
Reviewed-by: Mikio Hara <mikioh.mikioh@gmail.com>
Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com>
This commit is contained in:
Alex Brainman 2015-12-19 17:42:16 +11:00
parent 471b6ecf08
commit 2cf5f04ffd
1 changed files with 14 additions and 8 deletions

View File

@ -447,15 +447,14 @@ func TestInterfaceHardwareAddrWithGetmac(t *testing.T) {
if err != nil {
t.Fatal(err)
}
have := make([]string, 0)
have := make(map[string]string)
for _, ifi := range ift {
if ifi.Flags&FlagLoopback != 0 {
// no MAC address for loopback interfaces
continue
}
have = append(have, ifi.Name+"="+ifi.HardwareAddr.String())
have[ifi.Name] = ifi.HardwareAddr.String()
}
sort.Strings(have)
out, err := runCmd("getmac", "/fo", "list", "/v")
if err != nil {
@ -478,7 +477,7 @@ func TestInterfaceHardwareAddrWithGetmac(t *testing.T) {
//Physical Address: XX-XX-XX-XX-XX-XX
//Transport Name: Media disconnected
//
want := make([]string, 0)
want := make(map[string]string)
var name string
lines := bytes.Split(out, []byte{'\r', '\n'})
for _, line := range lines {
@ -505,13 +504,20 @@ func TestInterfaceHardwareAddrWithGetmac(t *testing.T) {
t.Fatal("empty address on \"Physical Address\" line: %q", line)
}
addr = strings.Replace(addr, "-", ":", -1)
want = append(want, name+"="+addr)
want[name] = addr
name = ""
}
}
sort.Strings(want)
if strings.Join(want, "/") != strings.Join(have, "/") {
t.Fatalf("unexpected MAC addresses %q, want %q", have, want)
for name, wantAddr := range want {
haveAddr, ok := have[name]
if !ok {
t.Errorf("getmac lists %q, but it could not be found among Go interfaces %v", name, have)
continue
}
if haveAddr != wantAddr {
t.Errorf("unexpected MAC address for %q - %v, want %v", name, haveAddr, wantAddr)
continue
}
}
}