@@ -189,6 +189,7 @@ func getIPNetWithString(ipaddrwithcidr string) *net.IPNet {
189189
190190func TestSetupRoutingForMultitenancy (t * testing.T ) {
191191 require := require .New (t ) //nolint:gocritic
192+
192193 type args struct {
193194 nwCfg * cni.NetworkConfig
194195 cnsNetworkConfig * cns.GetNetworkContainerResponse
@@ -204,31 +205,28 @@ func TestSetupRoutingForMultitenancy(t *testing.T) {
204205 expected args
205206 }{
206207 {
207- name : "test happy path " ,
208+ name : "adds default v4 route when SNAT disabled and SkipDefaultRoutes=false " ,
208209 args : args {
209210 nwCfg : & cni.NetworkConfig {
210211 MultiTenancy : true ,
211212 EnableSnatOnHost : false ,
212213 },
213214 cnsNetworkConfig : & cns.GetNetworkContainerResponse {
214215 IPConfiguration : cns.IPConfiguration {
215- IPSubnet : cns.IPSubnet {},
216- DNSServers : nil ,
217216 GatewayIPAddress : "10.0.0.1" ,
218217 },
219218 },
220- epInfo : & network.EndpointInfo {},
219+ epInfo : & network.EndpointInfo {}, // SkipDefaultRoutes defaults to false
221220 result : & network.InterfaceInfo {},
222221 },
222+ multitenancyClient : & Multitenancy {},
223223 expected : args {
224224 nwCfg : & cni.NetworkConfig {
225225 MultiTenancy : true ,
226226 EnableSnatOnHost : false ,
227227 },
228228 cnsNetworkConfig : & cns.GetNetworkContainerResponse {
229229 IPConfiguration : cns.IPConfiguration {
230- IPSubnet : cns.IPSubnet {},
231- DNSServers : nil ,
232230 GatewayIPAddress : "10.0.0.1" ,
233231 },
234232 },
@@ -250,11 +248,56 @@ func TestSetupRoutingForMultitenancy(t *testing.T) {
250248 },
251249 },
252250 },
251+ {
252+ name : "does not add default route when SkipDefaultRoutes=true" ,
253+ args : args {
254+ nwCfg : & cni.NetworkConfig {
255+ MultiTenancy : true ,
256+ EnableSnatOnHost : false ,
257+ },
258+ cnsNetworkConfig : & cns.GetNetworkContainerResponse {
259+ IPConfiguration : cns.IPConfiguration {
260+ GatewayIPAddress : "10.0.0.1" ,
261+ },
262+ },
263+ epInfo : & network.EndpointInfo {
264+ SkipDefaultRoutes : true ,
265+ },
266+ result : & network.InterfaceInfo {},
267+ },
268+ multitenancyClient : & Multitenancy {},
269+ expected : args {
270+ nwCfg : & cni.NetworkConfig {
271+ MultiTenancy : true ,
272+ EnableSnatOnHost : false ,
273+ },
274+ cnsNetworkConfig : & cns.GetNetworkContainerResponse {
275+ IPConfiguration : cns.IPConfiguration {
276+ GatewayIPAddress : "10.0.0.1" ,
277+ },
278+ },
279+ epInfo : & network.EndpointInfo {
280+ SkipDefaultRoutes : true ,
281+ Routes : nil , // unchanged
282+ },
283+ result : & network.InterfaceInfo {
284+ Routes : nil , // unchanged
285+ },
286+ },
287+ },
253288 }
289+
254290 for _ , tt := range tests {
255291 tt := tt
256292 t .Run (tt .name , func (t * testing.T ) {
257- tt .multitenancyClient .SetupRoutingForMultitenancy (tt .args .nwCfg , tt .args .cnsNetworkConfig , tt .args .azIpamResult , tt .args .epInfo , tt .args .result )
293+ tt .multitenancyClient .SetupRoutingForMultitenancy (
294+ tt .args .nwCfg ,
295+ tt .args .cnsNetworkConfig ,
296+ tt .args .azIpamResult ,
297+ tt .args .epInfo ,
298+ tt .args .result ,
299+ )
300+
258301 require .Exactly (tt .expected .nwCfg , tt .args .nwCfg )
259302 require .Exactly (tt .expected .cnsNetworkConfig , tt .args .cnsNetworkConfig )
260303 require .Exactly (tt .expected .azIpamResult , tt .args .azIpamResult )
@@ -861,4 +904,4 @@ func TestGetMultiTenancyCNIResultNotFound(t *testing.T) {
861904 }
862905 })
863906 }
864- }
907+ }
0 commit comments