@@ -85,6 +85,33 @@ func (c *MockCNSClient) RequestIPAddress(ctx context.Context, ipconfig cns.IPCon
8585 },
8686 }
8787 return result , nil
88+ case "invalidGateway" :
89+ result := & cns.IPConfigResponse {
90+ PodIpInfo : cns.PodIpInfo {
91+ PodIPConfig : cns.IPSubnet {
92+ IPAddress : "10.0.1.10" ,
93+ PrefixLength : 24 ,
94+ },
95+ NetworkContainerPrimaryIPConfig : cns.IPConfiguration {
96+ IPSubnet : cns.IPSubnet {
97+ IPAddress : "10.0.1.0" ,
98+ PrefixLength : 24 ,
99+ },
100+ DNSServers : nil ,
101+ GatewayIPAddress : "invalidgatewayip" ,
102+ },
103+ HostPrimaryIPInfo : cns.HostIPInfo {
104+ Gateway : "invalidgatewayip" ,
105+ PrimaryIP : "10.0.0.1" ,
106+ Subnet : "10.0.0.0/24" ,
107+ },
108+ },
109+ Response : cns.Response {
110+ ReturnCode : 0 ,
111+ Message : "" ,
112+ },
113+ }
114+ return result , nil
88115 default :
89116 result := & cns.IPConfigResponse {
90117 PodIpInfo : cns.PodIpInfo {
@@ -120,7 +147,7 @@ func (c *MockCNSClient) RequestIPs(ctx context.Context, ipconfig cns.IPConfigsRe
120147 switch ipconfig .InfraContainerID {
121148 case "failRequestCNSArgs" :
122149 return nil , errFoo
123- case "happyArgsSingle" , "failProcessCNSRespSingleIP" , "failRequestCNSArgsSingleIP" , "nilGateway" :
150+ case "happyArgsSingle" , "failProcessCNSRespSingleIP" , "failRequestCNSArgsSingleIP" , "nilGateway" , "invalidGateway" :
124151 e := & client.CNSClientError {}
125152 e .Code = types .UnsupportedAPI
126153 e .Err = errUnsupportedAPI
@@ -407,8 +434,27 @@ func TestCmdAdd(t *testing.T) {
407434 wantErr : false ,
408435 },
409436 {
410- name : "CNI add with nil gateway IP" ,
411- args : buildArgs ("nilGateway" , happyPodArgs , happyNetConfByteArr ),
437+ name : "CNI add with nil gateway IP" ,
438+ args : buildArgs ("nilGateway" , happyPodArgs , happyNetConfByteArr ),
439+ want : & types100.Result {
440+ CNIVersion : "1.0.0" ,
441+ Interfaces : nil ,
442+ IPs : []* types100.IPConfig {
443+ {
444+ Address : net.IPNet {
445+ IP : net .IPv4 (10 , 0 , 1 , 10 ),
446+ Mask : net .CIDRMask (24 , 32 ),
447+ },
448+ Gateway : nil , // No gateway
449+ },
450+ },
451+ DNS : cniTypes.DNS {},
452+ },
453+ wantErr : false ,
454+ },
455+ {
456+ name : "CNI add with invalid gateway IP" ,
457+ args : buildArgs ("invalidGateway" , happyPodArgs , happyNetConfByteArr ),
412458 wantErr : true ,
413459 },
414460 {
0 commit comments