@@ -564,39 +564,49 @@ func TestInterfaceHardwareAddrWithGetmac(t *testing.T) {
564
564
//Transport Name: Disconnected
565
565
//
566
566
want := make (map [string ]string )
567
- var name string
567
+ group := make (map [string ]string ) // name / values for single adapter
568
+ getValue := func (name string ) string {
569
+ value , found := group [name ]
570
+ if ! found {
571
+ t .Fatalf ("%q has no %q line in it" , group , name )
572
+ }
573
+ if value == "" {
574
+ t .Fatalf ("%q has empty %q value" , group , name )
575
+ }
576
+ return value
577
+ }
578
+ processGroup := func () {
579
+ if len (group ) == 0 {
580
+ return
581
+ }
582
+ tname := strings .ToLower (getValue ("Transport Name" ))
583
+ if tname == "n/a" {
584
+ // skip these
585
+ return
586
+ }
587
+ addr := strings .ToLower (getValue ("Physical Address" ))
588
+ if addr == "disabled" || addr == "n/a" {
589
+ // skip these
590
+ return
591
+ }
592
+ addr = strings .Replace (addr , "-" , ":" , - 1 )
593
+ cname := getValue ("Connection Name" )
594
+ want [cname ] = addr
595
+ group = nil
596
+ }
568
597
lines := bytes .Split (out , []byte {'\r' , '\n' })
569
598
for _ , line := range lines {
570
- if bytes .Contains (line , []byte ("Connection Name:" )) {
571
- f := bytes .Split (line , []byte {':' })
572
- if len (f ) != 2 {
573
- t .Fatalf ("unexpected \" Connection Name\" line: %q" , line )
574
- }
575
- name = string (bytes .TrimSpace (f [1 ]))
576
- if name == "" {
577
- t .Fatalf ("empty name on \" Connection Name\" line: %q" , line )
578
- }
599
+ if len (line ) == 0 {
600
+ processGroup ()
601
+ continue
579
602
}
580
- if bytes .Contains (line , []byte ("Physical Address:" )) {
581
- if name == "" {
582
- t .Fatalf ("no matching name found: %q" , string (out ))
583
- }
584
- f := bytes .Split (line , []byte {':' })
585
- if len (f ) != 2 {
586
- t .Fatalf ("unexpected \" Physical Address\" line: %q" , line )
587
- }
588
- addr := string (bytes .ToLower (bytes .TrimSpace (f [1 ])))
589
- if addr == "" {
590
- t .Fatalf ("empty address on \" Physical Address\" line: %q" , line )
591
- }
592
- if addr == "disabled" || addr == "n/a" {
593
- continue
594
- }
595
- addr = strings .Replace (addr , "-" , ":" , - 1 )
596
- want [name ] = addr
597
- name = ""
603
+ i := bytes .IndexByte (line , ':' )
604
+ if i == - 1 {
605
+ t .Fatalf ("line %q has no : in it" , line )
598
606
}
607
+ group [string (line [:i ])] = string (bytes .TrimSpace (line [i + 1 :]))
599
608
}
609
+ processGroup ()
600
610
601
611
for name , wantAddr := range want {
602
612
haveAddr , ok := have [name ]
0 commit comments