github.com/operator-framework/operator-lifecycle-manager@v0.30.0/pkg/lib/proxy/overridden_test.go (about) 1 package proxy_test 2 3 import ( 4 "strings" 5 "testing" 6 7 "github.com/operator-framework/operator-lifecycle-manager/pkg/lib/proxy" 8 9 "github.com/stretchr/testify/assert" 10 corev1 "k8s.io/api/core/v1" 11 ) 12 13 var ( 14 globalProxyConfig = []corev1.EnvVar{ 15 { 16 Name: "HTTP_PROXY", 17 Value: "http://foo.com:8080", 18 }, 19 { 20 Name: "HTTPS_PROXY", 21 Value: "https://foo.com:443", 22 }, 23 { 24 Name: "NO_PROXY", 25 Value: "a.com,b.com", 26 }, 27 } 28 ) 29 30 func TestIsOverridden(t *testing.T) { 31 tests := []struct { 32 name string 33 envVar []corev1.EnvVar 34 expected bool 35 }{ 36 { 37 name: "WithEmptyEnvVar", 38 envVar: []corev1.EnvVar{}, 39 expected: false, 40 }, 41 { 42 name: "WithNilEnvVar", 43 envVar: nil, 44 expected: false, 45 }, 46 { 47 name: "WithUnrelatedEnvVar", 48 envVar: []corev1.EnvVar{ 49 { 50 Name: "foo", 51 Value: "foo_value", 52 }, 53 }, 54 expected: false, 55 }, 56 { 57 name: "WithHTTP_PROXY", 58 envVar: []corev1.EnvVar{ 59 { 60 Name: envHTTPProxyName, 61 Value: "http://", 62 }, 63 }, 64 expected: true, 65 }, 66 { 67 name: "WithHTTPS_PROXY", 68 envVar: []corev1.EnvVar{ 69 { 70 Name: envHTTPSProxyName, 71 Value: "https://", 72 }, 73 }, 74 expected: true, 75 }, 76 { 77 name: "WithNO_PROXY", 78 envVar: []corev1.EnvVar{ 79 { 80 Name: envNoProxyName, 81 Value: "https://", 82 }, 83 }, 84 expected: true, 85 }, 86 { 87 name: "WithCaseSensitive", 88 envVar: []corev1.EnvVar{ 89 { 90 Name: strings.ToLower(envHTTPSProxyName), 91 Value: "http://", 92 }, 93 }, 94 expected: false, 95 }, 96 } 97 98 for _, tt := range tests { 99 t.Run(tt.name, func(t *testing.T) { 100 actual := proxy.IsOverridden(tt.envVar) 101 102 assert.Equal(t, tt.expected, actual) 103 }) 104 } 105 }