mirror of
https://github.com/golang/go
synced 2024-10-06 08:00:07 +00:00
net: adjust TestInterfaceHardwareAddrWithGetmac
Ignore adapters with "Transport Name: N/A" line in getmac command output. This allows us to skip duplicate MAC addresses. Fixes #19537. Change-Id: I6b7be9d31322f963e02023c8f1037f6e9042b479 Reviewed-on: https://go-review.googlesource.com/39071 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Avelino <t@avelino.xxx> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
b5e964cc1c
commit
0927b4728d
|
@ -564,39 +564,49 @@ func TestInterfaceHardwareAddrWithGetmac(t *testing.T) {
|
|||
//Transport Name: Disconnected
|
||||
//
|
||||
want := make(map[string]string)
|
||||
var name string
|
||||
group := make(map[string]string) // name / values for single adapter
|
||||
getValue := func(name string) string {
|
||||
value, found := group[name]
|
||||
if !found {
|
||||
t.Fatalf("%q has no %q line in it", group, name)
|
||||
}
|
||||
if value == "" {
|
||||
t.Fatalf("%q has empty %q value", group, name)
|
||||
}
|
||||
return value
|
||||
}
|
||||
processGroup := func() {
|
||||
if len(group) == 0 {
|
||||
return
|
||||
}
|
||||
tname := strings.ToLower(getValue("Transport Name"))
|
||||
if tname == "n/a" {
|
||||
// skip these
|
||||
return
|
||||
}
|
||||
addr := strings.ToLower(getValue("Physical Address"))
|
||||
if addr == "disabled" || addr == "n/a" {
|
||||
// skip these
|
||||
return
|
||||
}
|
||||
addr = strings.Replace(addr, "-", ":", -1)
|
||||
cname := getValue("Connection Name")
|
||||
want[cname] = addr
|
||||
group = nil
|
||||
}
|
||||
lines := bytes.Split(out, []byte{'\r', '\n'})
|
||||
for _, line := range lines {
|
||||
if bytes.Contains(line, []byte("Connection Name:")) {
|
||||
f := bytes.Split(line, []byte{':'})
|
||||
if len(f) != 2 {
|
||||
t.Fatalf("unexpected \"Connection Name\" line: %q", line)
|
||||
}
|
||||
name = string(bytes.TrimSpace(f[1]))
|
||||
if name == "" {
|
||||
t.Fatalf("empty name on \"Connection Name\" line: %q", line)
|
||||
}
|
||||
if len(line) == 0 {
|
||||
processGroup()
|
||||
continue
|
||||
}
|
||||
if bytes.Contains(line, []byte("Physical Address:")) {
|
||||
if name == "" {
|
||||
t.Fatalf("no matching name found: %q", string(out))
|
||||
}
|
||||
f := bytes.Split(line, []byte{':'})
|
||||
if len(f) != 2 {
|
||||
t.Fatalf("unexpected \"Physical Address\" line: %q", line)
|
||||
}
|
||||
addr := string(bytes.ToLower(bytes.TrimSpace(f[1])))
|
||||
if addr == "" {
|
||||
t.Fatalf("empty address on \"Physical Address\" line: %q", line)
|
||||
}
|
||||
if addr == "disabled" || addr == "n/a" {
|
||||
continue
|
||||
}
|
||||
addr = strings.Replace(addr, "-", ":", -1)
|
||||
want[name] = addr
|
||||
name = ""
|
||||
i := bytes.IndexByte(line, ':')
|
||||
if i == -1 {
|
||||
t.Fatalf("line %q has no : in it", line)
|
||||
}
|
||||
group[string(line[:i])] = string(bytes.TrimSpace(line[i+1:]))
|
||||
}
|
||||
processGroup()
|
||||
|
||||
for name, wantAddr := range want {
|
||||
haveAddr, ok := have[name]
|
||||
|
|
Loading…
Reference in a new issue