@@ -339,6 +339,68 @@ func TestMergeContainerEnv(t *testing.T) {
339339 }
340340}
341341
342+ func TestMergeContainerEnvProxyOverride (t * testing.T ) {
343+ tests := []struct {
344+ name string
345+ clusterProxyEnv []corev1.EnvVar
346+ userOverrideEnv []corev1.EnvVar
347+ expected []corev1.EnvVar
348+ }{
349+ {
350+ name : "user override replaces cluster proxy values" ,
351+ clusterProxyEnv : []corev1.EnvVar {
352+ {Name : "HTTP_PROXY" , Value : "http://cluster-proxy:3128" },
353+ },
354+ userOverrideEnv : []corev1.EnvVar {
355+ {Name : "HTTP_PROXY" , Value : "http://user-proxy:8080" },
356+ },
357+ expected : []corev1.EnvVar {
358+ {Name : "HTTP_PROXY" , Value : "http://user-proxy:8080" },
359+ },
360+ },
361+ {
362+ name : "user partial override keeps other cluster proxy values" ,
363+ clusterProxyEnv : []corev1.EnvVar {
364+ {Name : "HTTPS_PROXY" , Value : "https://cluster-proxy:3128" },
365+ {Name : "HTTP_PROXY" , Value : "http://cluster-proxy:3128" },
366+ },
367+ userOverrideEnv : []corev1.EnvVar {
368+ {Name : "HTTP_PROXY" , Value : "http://user-proxy:8080" },
369+ },
370+ expected : []corev1.EnvVar {
371+ {Name : "HTTPS_PROXY" , Value : "https://cluster-proxy:3128" },
372+ {Name : "HTTP_PROXY" , Value : "http://user-proxy:8080" },
373+ },
374+ },
375+ {
376+ name : "no cluster proxy, user override is applied" ,
377+ clusterProxyEnv : []corev1.EnvVar {},
378+ userOverrideEnv : []corev1.EnvVar {
379+ {Name : "HTTP_PROXY" , Value : "http://user-proxy:8080" },
380+ },
381+ expected : []corev1.EnvVar {
382+ {Name : "HTTP_PROXY" , Value : "http://user-proxy:8080" },
383+ },
384+ },
385+ {
386+ name : "cluster proxy present, no user override" ,
387+ clusterProxyEnv : []corev1.EnvVar {
388+ {Name : "HTTP_PROXY" , Value : "http://cluster-proxy:3128" },
389+ },
390+ userOverrideEnv : []corev1.EnvVar {},
391+ expected : []corev1.EnvVar {
392+ {Name : "HTTP_PROXY" , Value : "http://cluster-proxy:3128" },
393+ },
394+ },
395+ }
396+
397+ for _ , tc := range tests {
398+ envAfterProxy := mergeContainerEnvs ([]corev1.EnvVar {}, tc .clusterProxyEnv )
399+ finalEnv := mergeContainerEnvs (envAfterProxy , tc .userOverrideEnv )
400+ require .Equal (t , tc .expected , finalEnv )
401+ }
402+ }
403+
342404func TestMergeContainerArgs (t * testing.T ) {
343405 tests := []struct {
344406 name string
0 commit comments