Skip to content

Commit

Permalink
test(bridge): add more mockup 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 Aug 28, 2023
1 parent bfea91c commit c7aae57
Showing 1 changed file with 53 additions and 3 deletions.
56 changes: 53 additions & 3 deletions pkg/evpn/bridge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,30 @@ func Test_CreateLogicalBridge(t *testing.T) {
"Failed to call LinkAdd",
false,
},
"failed LinkSetMaster call": {
testLogicalBridgeID,
&testLogicalBridge,
nil,
codes.Unknown,
"Failed to call LinkSetMaster",
false,
},
"failed LinkSetUp call": {
testLogicalBridgeID,
&testLogicalBridge,
nil,
codes.Unknown,
"Failed to call LinkSetUp",
false,
},
"failed BridgeVlanAdd call": {
testLogicalBridgeID,
&testLogicalBridge,
nil,
codes.Unknown,
"Failed to call BridgeVlanAdd",
false,
},
}

// run tests
Expand Down Expand Up @@ -166,17 +190,43 @@ func Test_CreateLogicalBridge(t *testing.T) {
}

// TODO: refactor this mocking
if strings.Contains(name, "LinkByName") {
if strings.Contains(name, "failed LinkByName") {
mockNetlink.EXPECT().LinkByName(tenantbridgeName).Return(nil, errors.New(tt.errMsg)).Once()
}
if strings.Contains(name, "LinkAdd") {
} else if strings.Contains(name, "failed LinkAdd") {
// myip := net.ParseIP("10.0.0.2")
myip := make(net.IP, 4)
binary.BigEndian.PutUint32(myip, 167772162)
vxlan := &netlink.Vxlan{LinkAttrs: netlink.LinkAttrs{Name: testLogicalBridgeID}, VxlanId: int(*testLogicalBridge.Spec.Vni), Port: 4789, Learning: false, SrcAddr: myip}
bridge := &netlink.Bridge{LinkAttrs: netlink.LinkAttrs{Name: tenantbridgeName}}
mockNetlink.EXPECT().LinkByName(tenantbridgeName).Return(bridge, nil).Once()
mockNetlink.EXPECT().LinkAdd(vxlan).Return(errors.New(tt.errMsg)).Once()
} else if strings.Contains(name, "failed LinkSetMaster") {
myip := make(net.IP, 4)
binary.BigEndian.PutUint32(myip, 167772162)
vxlan := &netlink.Vxlan{LinkAttrs: netlink.LinkAttrs{Name: testLogicalBridgeID}, VxlanId: int(*testLogicalBridge.Spec.Vni), Port: 4789, Learning: false, SrcAddr: myip}
bridge := &netlink.Bridge{LinkAttrs: netlink.LinkAttrs{Name: tenantbridgeName}}
mockNetlink.EXPECT().LinkByName(tenantbridgeName).Return(bridge, nil).Once()
mockNetlink.EXPECT().LinkAdd(vxlan).Return(nil).Once()
mockNetlink.EXPECT().LinkSetMaster(vxlan, bridge).Return(errors.New(tt.errMsg)).Once()
} else if strings.Contains(name, "failed LinkSetUp") {
myip := make(net.IP, 4)
binary.BigEndian.PutUint32(myip, 167772162)
vxlan := &netlink.Vxlan{LinkAttrs: netlink.LinkAttrs{Name: testLogicalBridgeID}, VxlanId: int(*testLogicalBridge.Spec.Vni), Port: 4789, Learning: false, SrcAddr: myip}
bridge := &netlink.Bridge{LinkAttrs: netlink.LinkAttrs{Name: tenantbridgeName}}
mockNetlink.EXPECT().LinkByName(tenantbridgeName).Return(bridge, nil).Once()
mockNetlink.EXPECT().LinkAdd(vxlan).Return(nil).Once()
mockNetlink.EXPECT().LinkSetMaster(vxlan, bridge).Return(nil).Once()
mockNetlink.EXPECT().LinkSetUp(vxlan).Return(errors.New(tt.errMsg)).Once()
} else if strings.Contains(name, "failed BridgeVlanAdd") {
myip := make(net.IP, 4)
binary.BigEndian.PutUint32(myip, 167772162)
vxlan := &netlink.Vxlan{LinkAttrs: netlink.LinkAttrs{Name: testLogicalBridgeID}, VxlanId: int(*testLogicalBridge.Spec.Vni), Port: 4789, Learning: false, SrcAddr: myip}
bridge := &netlink.Bridge{LinkAttrs: netlink.LinkAttrs{Name: tenantbridgeName}}
mockNetlink.EXPECT().LinkByName(tenantbridgeName).Return(bridge, nil).Once()
mockNetlink.EXPECT().LinkAdd(vxlan).Return(nil).Once()
mockNetlink.EXPECT().LinkSetMaster(vxlan, bridge).Return(nil).Once()
mockNetlink.EXPECT().LinkSetUp(vxlan).Return(nil).Once()
mockNetlink.EXPECT().BridgeVlanAdd(vxlan, uint16(testLogicalBridge.Spec.VlanId), true, true, false, false).Return(errors.New(tt.errMsg)).Once()
}

request := &pb.CreateLogicalBridgeRequest{LogicalBridge: tt.in, LogicalBridgeId: tt.id}
Expand Down

0 comments on commit c7aae57

Please sign in to comment.