Skip to content

Commit

Permalink
test(svi): add few more mock tests
Browse files Browse the repository at this point in the history
Signed-off-by: Boris Glimcher <Boris.Glimcher@emc.com>
  • Loading branch information
glimchb committed Sep 6, 2023
1 parent 7cab4e3 commit 4f1ecbd
Showing 1 changed file with 97 additions and 1 deletion.
98 changes: 97 additions & 1 deletion pkg/evpn/svi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func Test_CreateSvi(t *testing.T) {
exist: false,
on: nil,
},
"failed LinkByName call": {
"failed bridge LinkByName call": {
id: testSviID,
in: &testSvi,
out: nil,
Expand Down Expand Up @@ -258,6 +258,102 @@ func Test_CreateSvi(t *testing.T) {
mockNetlink.EXPECT().LinkSetHardwareAddr(vlandev, mac).Return(errors.New(errMsg)).Once()
},
},
"failed AddrAdd call": {
id: testSviID,
in: &testSvi,
out: nil,
errCode: codes.Unknown,
errMsg: "Failed to call AddrAdd",
exist: false,
on: func(mockNetlink *mocks.Netlink, errMsg string) {
vid := uint16(testLogicalBridge.Spec.VlanId)
bridge := &netlink.Bridge{LinkAttrs: netlink.LinkAttrs{Name: tenantbridgeName}}
mockNetlink.EXPECT().LinkByName(tenantbridgeName).Return(bridge, nil).Once()
mockNetlink.EXPECT().BridgeVlanAdd(bridge, vid, false, false, true, false).Return(nil).Once()
vlanName := fmt.Sprintf("vlan%d", vid)
vlandev := &netlink.Vlan{LinkAttrs: netlink.LinkAttrs{Name: vlanName, ParentIndex: bridge.Attrs().Index}, VlanId: int(vid)}
mockNetlink.EXPECT().LinkAdd(vlandev).Return(nil).Once()
mac := net.HardwareAddr(testSvi.Spec.MacAddress[:])
mockNetlink.EXPECT().LinkSetHardwareAddr(vlandev, mac).Return(nil).Once()
myip := make(net.IP, 4)
addr := &netlink.Addr{IPNet: &net.IPNet{IP: myip, Mask: net.CIDRMask(24, 32)}}
mockNetlink.EXPECT().AddrAdd(vlandev, addr).Return(errors.New(errMsg)).Once()
},
},
"failed LinkByName call": {
id: testSviID,
in: &testSvi,
out: nil,
errCode: codes.NotFound,
errMsg: fmt.Sprintf("unable to find key %v", testVrfName),
exist: false,
on: func(mockNetlink *mocks.Netlink, errMsg string) {
vid := uint16(testLogicalBridge.Spec.VlanId)
bridge := &netlink.Bridge{LinkAttrs: netlink.LinkAttrs{Name: tenantbridgeName}}
mockNetlink.EXPECT().LinkByName(tenantbridgeName).Return(bridge, nil).Once()
mockNetlink.EXPECT().BridgeVlanAdd(bridge, vid, false, false, true, false).Return(nil).Once()
vlanName := fmt.Sprintf("vlan%d", vid)
vlandev := &netlink.Vlan{LinkAttrs: netlink.LinkAttrs{Name: vlanName, ParentIndex: bridge.Attrs().Index}, VlanId: int(vid)}
mockNetlink.EXPECT().LinkAdd(vlandev).Return(nil).Once()
mac := net.HardwareAddr(testSvi.Spec.MacAddress[:])
mockNetlink.EXPECT().LinkSetHardwareAddr(vlandev, mac).Return(nil).Once()
myip := make(net.IP, 4)
addr := &netlink.Addr{IPNet: &net.IPNet{IP: myip, Mask: net.CIDRMask(24, 32)}}
mockNetlink.EXPECT().AddrAdd(vlandev, addr).Return(nil).Once()
mockNetlink.EXPECT().LinkByName(testVrfID).Return(nil, errors.New(errMsg)).Once()
},
},
"failed LinkSetMaster call": {
id: testSviID,
in: &testSvi,
out: nil,
errCode: codes.Unknown,
errMsg: "Failed to call LinkSetMaster",
exist: false,
on: func(mockNetlink *mocks.Netlink, errMsg string) {
vid := uint16(testLogicalBridge.Spec.VlanId)
bridge := &netlink.Bridge{LinkAttrs: netlink.LinkAttrs{Name: tenantbridgeName}}
mockNetlink.EXPECT().LinkByName(tenantbridgeName).Return(bridge, nil).Once()
mockNetlink.EXPECT().BridgeVlanAdd(bridge, vid, false, false, true, false).Return(nil).Once()
vlanName := fmt.Sprintf("vlan%d", vid)
vlandev := &netlink.Vlan{LinkAttrs: netlink.LinkAttrs{Name: vlanName, ParentIndex: bridge.Attrs().Index}, VlanId: int(vid)}
mockNetlink.EXPECT().LinkAdd(vlandev).Return(nil).Once()
mac := net.HardwareAddr(testSvi.Spec.MacAddress[:])
mockNetlink.EXPECT().LinkSetHardwareAddr(vlandev, mac).Return(nil).Once()
myip := make(net.IP, 4)
addr := &netlink.Addr{IPNet: &net.IPNet{IP: myip, Mask: net.CIDRMask(24, 32)}}
mockNetlink.EXPECT().AddrAdd(vlandev, addr).Return(nil).Once()
vrfdev := &netlink.Vrf{LinkAttrs: netlink.LinkAttrs{Name: testVrfID}, Table: 1001}
mockNetlink.EXPECT().LinkByName(testVrfID).Return(vrfdev, nil).Once()
mockNetlink.EXPECT().LinkSetMaster(vlandev, vrfdev).Return(errors.New(errMsg)).Once()
},
},
"failed LinkSetUp call": {
id: testSviID,
in: &testSvi,
out: nil,
errCode: codes.Unknown,
errMsg: "Failed to call LinkSetUp",
exist: false,
on: func(mockNetlink *mocks.Netlink, errMsg string) {
vid := uint16(testLogicalBridge.Spec.VlanId)
bridge := &netlink.Bridge{LinkAttrs: netlink.LinkAttrs{Name: tenantbridgeName}}
mockNetlink.EXPECT().LinkByName(tenantbridgeName).Return(bridge, nil).Once()
mockNetlink.EXPECT().BridgeVlanAdd(bridge, vid, false, false, true, false).Return(nil).Once()
vlanName := fmt.Sprintf("vlan%d", vid)
vlandev := &netlink.Vlan{LinkAttrs: netlink.LinkAttrs{Name: vlanName, ParentIndex: bridge.Attrs().Index}, VlanId: int(vid)}
mockNetlink.EXPECT().LinkAdd(vlandev).Return(nil).Once()
mac := net.HardwareAddr(testSvi.Spec.MacAddress[:])
mockNetlink.EXPECT().LinkSetHardwareAddr(vlandev, mac).Return(nil).Once()
myip := make(net.IP, 4)
addr := &netlink.Addr{IPNet: &net.IPNet{IP: myip, Mask: net.CIDRMask(24, 32)}}
mockNetlink.EXPECT().AddrAdd(vlandev, addr).Return(nil).Once()
vrfdev := &netlink.Vrf{LinkAttrs: netlink.LinkAttrs{Name: testVrfID}, Table: 1001}
mockNetlink.EXPECT().LinkByName(testVrfID).Return(vrfdev, nil).Once()
mockNetlink.EXPECT().LinkSetMaster(vlandev, vrfdev).Return(nil).Once()
mockNetlink.EXPECT().LinkSetUp(vlandev).Return(errors.New(errMsg)).Once()
},
},
}

// run tests
Expand Down

0 comments on commit 4f1ecbd

Please sign in to comment.