github.com/vmware/govmomi@v0.51.0/toolbox/guest_info_test.go (about) 1 // © Broadcom. All Rights Reserved. 2 // The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. 3 // SPDX-License-Identifier: Apache-2.0 4 5 package toolbox 6 7 import ( 8 "net" 9 "reflect" 10 "testing" 11 ) 12 13 func TestDefaultGuestNicProto(t *testing.T) { 14 p := DefaultGuestNicInfo() 15 16 info := p.V3 17 18 for _, nic := range info.Nics { 19 if len(nic.MacAddress) == 0 { 20 continue 21 } 22 _, err := net.ParseMAC(nic.MacAddress) 23 if err != nil { 24 t.Errorf("invalid MAC %s: %s", nic.MacAddress, err) 25 } 26 } 27 28 b, err := EncodeXDR(p) 29 if err != nil { 30 t.Fatal(err) 31 } 32 33 var dp GuestNicInfo 34 err = DecodeXDR(b, &dp) 35 if err != nil { 36 t.Fatal(err) 37 } 38 39 if !reflect.DeepEqual(p, &dp) { 40 t.Error("decode mismatch") 41 } 42 } 43 44 func TestMaxGuestNic(t *testing.T) { 45 p := DefaultGuestNicInfo() 46 47 maxNics = len(p.V3.Nics) 48 49 a, _ := net.Interfaces() 50 a = append(a, a...) // double the number of interfaces returned 51 netInterfaces = func() ([]net.Interface, error) { 52 return a, nil 53 } 54 55 p = DefaultGuestNicInfo() 56 57 l := len(p.V3.Nics) 58 if l != maxNics { 59 t.Errorf("Nics=%d", l) 60 } 61 }