Skip to content

Commit c19abe3

Browse files
committed
net: ignore duplicate interfaces in TestInterfaceHardwareAddrWithGetmac
Sometimes getmac lists many interfaces for the same MAC address, while Interfaces returns only single name for that address. Adjust the test to ignore the names that are not returned by the Interfaces. Fixes #21027 Change-Id: I08d98746a7c669f2d730dba2da36e07451a6f405 Reviewed-on: https://go-review.googlesource.com/59411 Reviewed-by: Mikio Hara <[email protected]>
1 parent dc3a4e4 commit c19abe3

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

src/net/net_windows_test.go

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -608,15 +608,34 @@ func TestInterfaceHardwareAddrWithGetmac(t *testing.T) {
608608
}
609609
processGroup()
610610

611+
dups := make(map[string][]string)
612+
for name, addr := range want {
613+
if _, ok := dups[addr]; !ok {
614+
dups[addr] = make([]string, 0)
615+
}
616+
dups[addr] = append(dups[addr], name)
617+
}
618+
619+
nextWant:
611620
for name, wantAddr := range want {
612-
haveAddr, ok := have[name]
613-
if !ok {
614-
t.Errorf("getmac lists %q, but it could not be found among Go interfaces %v", name, have)
621+
if haveAddr, ok := have[name]; ok {
622+
if haveAddr != wantAddr {
623+
t.Errorf("unexpected MAC address for %q - %v, want %v", name, haveAddr, wantAddr)
624+
}
615625
continue
616626
}
617-
if haveAddr != wantAddr {
618-
t.Errorf("unexpected MAC address for %q - %v, want %v", name, haveAddr, wantAddr)
619-
continue
627+
// We could not find the interface in getmac output by name.
628+
// But sometimes getmac lists many interface names
629+
// for the same MAC address. If that is the case here,
630+
// and we can match at least one of those names,
631+
// let's ignore the other names.
632+
if dupNames, ok := dups[wantAddr]; ok && len(dupNames) > 1 {
633+
for _, dupName := range dupNames {
634+
if haveAddr, ok := have[dupName]; ok && haveAddr == wantAddr {
635+
continue nextWant
636+
}
637+
}
620638
}
639+
t.Errorf("getmac lists %q, but it could not be found among Go interfaces %v", name, have)
621640
}
622641
}

0 commit comments

Comments
 (0)