github.com/operator-framework/operator-lifecycle-manager@v0.30.0/pkg/lib/proxy/envvar_test.go (about)

     1  package proxy_test
     2  
     3  import (
     4  	"testing"
     5  
     6  	apiconfigv1 "github.com/openshift/api/config/v1"
     7  	"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/proxy"
     8  	"github.com/stretchr/testify/assert"
     9  	corev1 "k8s.io/api/core/v1"
    10  )
    11  
    12  const (
    13  	envHTTPProxyName  = "HTTP_PROXY"
    14  	envHTTPSProxyName = "HTTPS_PROXY"
    15  	envNoProxyName    = "NO_PROXY"
    16  )
    17  
    18  func TestToEnvVar(t *testing.T) {
    19  	tests := []struct {
    20  		name       string
    21  		proxy      *apiconfigv1.Proxy
    22  		envVarWant []corev1.EnvVar
    23  	}{
    24  		{
    25  			name: "WithSet",
    26  			proxy: &apiconfigv1.Proxy{
    27  				Status: apiconfigv1.ProxyStatus{
    28  					HTTPProxy:  "http://",
    29  					HTTPSProxy: "https://",
    30  					NoProxy:    "foo,bar",
    31  				},
    32  			},
    33  			envVarWant: []corev1.EnvVar{
    34  				{
    35  					Name:  envHTTPProxyName,
    36  					Value: "http://",
    37  				},
    38  				{
    39  					Name:  envHTTPSProxyName,
    40  					Value: "https://",
    41  				},
    42  				{
    43  					Name:  envNoProxyName,
    44  					Value: "foo,bar",
    45  				},
    46  			},
    47  		},
    48  
    49  		{
    50  			name: "WithUnset",
    51  			proxy: &apiconfigv1.Proxy{
    52  				Status: apiconfigv1.ProxyStatus{
    53  					HTTPProxy:  "http://",
    54  					HTTPSProxy: "",
    55  					NoProxy:    "",
    56  				},
    57  			},
    58  			envVarWant: []corev1.EnvVar{
    59  				{
    60  					Name:  envHTTPProxyName,
    61  					Value: "http://",
    62  				},
    63  				{
    64  					Name:  envHTTPSProxyName,
    65  					Value: "",
    66  				},
    67  				{
    68  					Name:  envNoProxyName,
    69  					Value: "",
    70  				},
    71  			},
    72  		},
    73  	}
    74  
    75  	for _, tt := range tests {
    76  		t.Run(tt.name, func(t *testing.T) {
    77  			envVarGot := proxy.ToEnvVar(tt.proxy)
    78  
    79  			assert.NotNil(t, envVarGot)
    80  			assert.Equal(t, tt.envVarWant, envVarGot)
    81  
    82  		})
    83  	}
    84  
    85  }