diff options
| author | Alex Brainman <alex.brainman@gmail.com> | 2017-08-28 12:21:44 +1000 |
|---|---|---|
| committer | Alex Brainman <alex.brainman@gmail.com> | 2017-11-10 23:18:17 +0000 |
| commit | c19abe30a00058dbf0950f30d5b7c2e451e676a3 (patch) | |
| tree | 994b2ac277ef0ac5f5220aa2b5253b2d3b5b0b15 /src/net/net_windows_test.go | |
| parent | dc3a4e4bca1eb0fed3304d22875ca26964091e82 (diff) | |
| download | go-c19abe30a00058dbf0950f30d5b7c2e451e676a3.tar.xz | |
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 <mikioh.mikioh@gmail.com>
Diffstat (limited to 'src/net/net_windows_test.go')
| -rw-r--r-- | src/net/net_windows_test.go | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/src/net/net_windows_test.go b/src/net/net_windows_test.go index 04416129eb..db211e9d6e 100644 --- a/src/net/net_windows_test.go +++ b/src/net/net_windows_test.go @@ -608,15 +608,34 @@ func TestInterfaceHardwareAddrWithGetmac(t *testing.T) { } processGroup() + dups := make(map[string][]string) + for name, addr := range want { + if _, ok := dups[addr]; !ok { + dups[addr] = make([]string, 0) + } + dups[addr] = append(dups[addr], name) + } + +nextWant: 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) + if haveAddr, ok := have[name]; ok { + if haveAddr != wantAddr { + t.Errorf("unexpected MAC address for %q - %v, want %v", name, haveAddr, wantAddr) + } continue } - if haveAddr != wantAddr { - t.Errorf("unexpected MAC address for %q - %v, want %v", name, haveAddr, wantAddr) - continue + // We could not find the interface in getmac output by name. + // But sometimes getmac lists many interface names + // for the same MAC address. If that is the case here, + // and we can match at least one of those names, + // let's ignore the other names. + if dupNames, ok := dups[wantAddr]; ok && len(dupNames) > 1 { + for _, dupName := range dupNames { + if haveAddr, ok := have[dupName]; ok && haveAddr == wantAddr { + continue nextWant + } + } } + t.Errorf("getmac lists %q, but it could not be found among Go interfaces %v", name, have) } } |
