Commit 0927b472 authored by Alex Brainman's avatar Alex Brainman

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/39071Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: default avatarAvelino <t@avelino.xxx>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent b5e964cc
...@@ -564,39 +564,49 @@ func TestInterfaceHardwareAddrWithGetmac(t *testing.T) { ...@@ -564,39 +564,49 @@ func TestInterfaceHardwareAddrWithGetmac(t *testing.T) {
//Transport Name: Disconnected //Transport Name: Disconnected
// //
want := make(map[string]string) want := make(map[string]string)
var name string group := make(map[string]string) // name / values for single adapter
lines := bytes.Split(out, []byte{'\r', '\n'}) getValue := func(name string) string {
for _, line := range lines { value, found := group[name]
if bytes.Contains(line, []byte("Connection Name:")) { if !found {
f := bytes.Split(line, []byte{':'}) t.Fatalf("%q has no %q line in it", group, name)
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 value == "" {
t.Fatalf("%q has empty %q value", group, name)
} }
if bytes.Contains(line, []byte("Physical Address:")) { return value
if name == "" {
t.Fatalf("no matching name found: %q", string(out))
} }
f := bytes.Split(line, []byte{':'}) processGroup := func() {
if len(f) != 2 { if len(group) == 0 {
t.Fatalf("unexpected \"Physical Address\" line: %q", line) return
} }
addr := string(bytes.ToLower(bytes.TrimSpace(f[1]))) tname := strings.ToLower(getValue("Transport Name"))
if addr == "" { if tname == "n/a" {
t.Fatalf("empty address on \"Physical Address\" line: %q", line) // skip these
return
} }
addr := strings.ToLower(getValue("Physical Address"))
if addr == "disabled" || addr == "n/a" { if addr == "disabled" || addr == "n/a" {
continue // skip these
return
} }
addr = strings.Replace(addr, "-", ":", -1) addr = strings.Replace(addr, "-", ":", -1)
want[name] = addr cname := getValue("Connection Name")
name = "" want[cname] = addr
group = nil
}
lines := bytes.Split(out, []byte{'\r', '\n'})
for _, line := range lines {
if len(line) == 0 {
processGroup()
continue
}
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 { for name, wantAddr := range want {
haveAddr, ok := have[name] haveAddr, ok := have[name]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment