Skip to content

Commit a01bfd0

Browse files
committed
test options set in invoker propagate to all endpoint infos
1 parent 46bbe04 commit a01bfd0

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

cni/network/invoker_mock.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ type MockIpamInvoker struct {
3131
delegatedVMNIC bool
3232
delegatedVMNICFail bool
3333
ipMap map[string]bool
34-
customReturn map[string]network.InterfaceInfo
34+
add func(opt IPAMAddConfig) (ipamAddResult IPAMAddResult, err error)
3535
}
3636

3737
func NewMockIpamInvoker(ipv6, v4Fail, v6Fail, delegatedVMNIC, delegatedVMNICFail bool) *MockIpamInvoker {
@@ -47,8 +47,11 @@ func NewMockIpamInvoker(ipv6, v4Fail, v6Fail, delegatedVMNIC, delegatedVMNICFail
4747

4848
func NewCustomMockIpamInvoker(customReturn map[string]network.InterfaceInfo) *MockIpamInvoker {
4949
return &MockIpamInvoker{
50-
customReturn: customReturn,
51-
50+
add: func(opt IPAMAddConfig) (ipamAddResult IPAMAddResult, err error) {
51+
ipamAddResult = IPAMAddResult{interfaceInfo: make(map[string]network.InterfaceInfo)}
52+
ipamAddResult.interfaceInfo = customReturn
53+
return ipamAddResult, nil
54+
},
5255
ipMap: make(map[string]bool),
5356
}
5457
}
@@ -112,9 +115,8 @@ func (invoker *MockIpamInvoker) Add(opt IPAMAddConfig) (ipamAddResult IPAMAddRes
112115
}
113116
}
114117

115-
if invoker.customReturn != nil {
116-
ipamAddResult.interfaceInfo = invoker.customReturn
117-
return ipamAddResult, nil
118+
if invoker.add != nil {
119+
return invoker.add(opt)
118120
}
119121

120122
return ipamAddResult, nil

cni/network/network_linux_test.go

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/Azure/azure-container-networking/platform"
1717
"github.com/Azure/azure-container-networking/telemetry"
1818
cniSkel "github.com/containernetworking/cni/pkg/skel"
19+
"github.com/containernetworking/cni/pkg/types"
1920
"github.com/stretchr/testify/assert"
2021
"github.com/stretchr/testify/require"
2122
)
@@ -333,11 +334,19 @@ func TestPluginLinuxAdd(t *testing.T) {
333334
// Based on a live swiftv2 linux cluster's cns invoker response
334335
name: "Add Happy Path Swiftv2",
335336
plugin: &NetPlugin{
336-
Plugin: resources.Plugin,
337-
nm: network.NewMockNetworkmanager(network.NewMockEndpointClient(nil)),
338-
tb: &telemetry.TelemetryBuffer{},
339-
report: &telemetry.CNIReport{},
340-
ipamInvoker: NewCustomMockIpamInvoker(GetTestCNSResponseSecondaryLinux(macAddress)),
337+
Plugin: resources.Plugin,
338+
nm: network.NewMockNetworkmanager(network.NewMockEndpointClient(nil)),
339+
tb: &telemetry.TelemetryBuffer{},
340+
report: &telemetry.CNIReport{},
341+
ipamInvoker: &MockIpamInvoker{
342+
add: func(opt IPAMAddConfig) (ipamAddResult IPAMAddResult, err error) {
343+
ipamAddResult = IPAMAddResult{interfaceInfo: make(map[string]network.InterfaceInfo)}
344+
ipamAddResult.interfaceInfo = GetTestCNSResponseSecondaryLinux(macAddress)
345+
opt.options["testflag"] = "copy"
346+
return ipamAddResult, nil
347+
},
348+
ipMap: make(map[string]bool),
349+
},
341350
netClient: &InterfaceGetterMock{
342351
// used in secondary find master interface
343352
interfaces: []net.Interface{
@@ -396,7 +405,9 @@ func TestPluginLinuxAdd(t *testing.T) {
396405
NetNsPath: "bc526fae-4ba0-4e80-bc90-ad721e5850bf",
397406
NetNs: "bc526fae-4ba0-4e80-bc90-ad721e5850bf",
398407
HostSubnetPrefix: "10.224.0.0/16",
399-
Options: map[string]interface{}{},
408+
Options: map[string]interface{}{
409+
"testflag": "copy",
410+
},
400411
// matches with cns ip configuration
401412
IPAddresses: []net.IPNet{
402413
{
@@ -445,7 +456,9 @@ func TestPluginLinuxAdd(t *testing.T) {
445456
NetNsPath: "bc526fae-4ba0-4e80-bc90-ad721e5850bf",
446457
NetNs: "bc526fae-4ba0-4e80-bc90-ad721e5850bf",
447458
HostSubnetPrefix: "<nil>",
448-
Options: map[string]interface{}{},
459+
Options: map[string]interface{}{
460+
"testflag": "copy",
461+
},
449462
// matches with cns ip configuration
450463
IPAddresses: []net.IPNet{
451464
{

0 commit comments

Comments
 (0)