Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add uts for cni add function #3069

Merged
merged 9 commits into from
Oct 16, 2024
14 changes: 8 additions & 6 deletions cni/network/invoker_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type MockIpamInvoker struct {
delegatedVMNIC bool
delegatedVMNICFail bool
ipMap map[string]bool
customReturn map[string]network.InterfaceInfo
add func(opt IPAMAddConfig) (ipamAddResult IPAMAddResult, err error)
}

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

func NewCustomMockIpamInvoker(customReturn map[string]network.InterfaceInfo) *MockIpamInvoker {
return &MockIpamInvoker{
customReturn: customReturn,

add: func(_ IPAMAddConfig) (ipamAddResult IPAMAddResult, err error) {
ipamAddResult = IPAMAddResult{interfaceInfo: make(map[string]network.InterfaceInfo)}
ipamAddResult.interfaceInfo = customReturn
return ipamAddResult, nil
},
ipMap: make(map[string]bool),
}
}
Expand Down Expand Up @@ -112,9 +115,8 @@ func (invoker *MockIpamInvoker) Add(opt IPAMAddConfig) (ipamAddResult IPAMAddRes
}
}

if invoker.customReturn != nil {
ipamAddResult.interfaceInfo = invoker.customReturn
return ipamAddResult, nil
if invoker.add != nil {
return invoker.add(opt)
}

return ipamAddResult, nil
Expand Down
1 change: 1 addition & 0 deletions cni/network/network_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func setNetworkOptions(cnsNwConfig *cns.GetNetworkContainerResponse, nwInfo *net
}
}

// update epInfo data field, allow host to nc, allow nc to host, and network container id
func setEndpointOptions(cnsNwConfig *cns.GetNetworkContainerResponse, epInfo *network.EndpointInfo, vethName string) {
if cnsNwConfig != nil && cnsNwConfig.MultiTenancyInfo.ID != 0 {
logger.Info("Setting Endpoint Options")
Expand Down
Loading
Loading