github.com/mirantis/virtlet@v1.5.2-0.20191204181327-1659b8a48e9b/pkg/utils/iplink_parser_test.go (about) 1 /* 2 Copyright 2018 Mirantis 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package utils 18 19 import ( 20 "reflect" 21 "testing" 22 ) 23 24 func TestIPLinkParser(t *testing.T) { 25 tests := []struct { 26 str []byte 27 vfinfos []VFInfo 28 }{ 29 { 30 []byte("4: enp6s0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000\n" + 31 " link/ether e4:1d:2d:13:ed:30 brd ff:ff:ff:ff:ff:ff\n" + 32 " vf 0 MAC 00:00:00:00:00:00, vlan 4095, spoof checking off, link-state auto\n" + 33 " vf 1 MAC aa:bb:cc:dd:ee:ff, vlan 1, spoof checking on, link-state enable\n" + 34 " vf 2 MAC aa:bb:cc:dd:ee:fe, vlan 2, spoof checking on, link-state disable\n"), 35 []VFInfo{ 36 {ID: 0, Mac: "00:00:00:00:00:00", VLanID: 4095}, 37 {ID: 1, Mac: "aa:bb:cc:dd:ee:ff", VLanID: 1, SpoofChecking: true, LinkState: &[]bool{true}[0]}, 38 {ID: 2, Mac: "aa:bb:cc:dd:ee:fe", VLanID: 2, SpoofChecking: true, LinkState: &[]bool{false}[0]}, 39 }, 40 }, 41 } 42 43 for _, test := range tests { 44 vfinfos, err := ParseIPLinkOutput(test.str) 45 if err != nil { 46 t.Errorf("Unexpected error during parsing of test data: %v", err) 47 } 48 if len(vfinfos) != len(test.vfinfos) { 49 t.Errorf("Expected %d infos about vfs while got %d", len(test.vfinfos), len(vfinfos)) 50 } 51 if !reflect.DeepEqual(vfinfos, test.vfinfos) { 52 t.Errorf("While expected %v got %v", test.vfinfos, vfinfos) 53 } 54 } 55 }