github.com/verrazzano/verrazzano@v1.7.1/tools/charts-manager/vcm/pkg/helm/helm_test.go (about) 1 // Copyright (c) 2023, Oracle and/or its affiliates. 2 // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. 3 4 package helm 5 6 import ( 7 "os" 8 "testing" 9 10 "github.com/stretchr/testify/assert" 11 vcmtesthelpers "github.com/verrazzano/verrazzano/tools/charts-manager/vcm/tests/pkg/helpers" 12 ) 13 14 const ( 15 testData = "testdata" 16 testChart = "testChart" 17 testVersion = "x.y.z" 18 testChartsDir = "testdata/charts" 19 testRepoConfig = testData + "/repositories.yaml" 20 testRepoCache = testData + "/repocache" 21 envVarRepoConfig = "HELM_REPOSITORY_CONFIG" 22 envVarRepoCache = "HELM_REPOSITORY_CACHE" 23 ) 24 25 var prevRepoConfig = os.Getenv(envVarRepoConfig) 26 var prevRepoCache = os.Getenv(envVarRepoCache) 27 28 // TestNewHelmConfig tests that function NewHelmConfig succeeds for default inputs 29 // GIVEN a call to NewHelmConfig 30 // 31 // WHEN helm repo env variables are correctly set 32 // THEN the NewHelmConfig returns a valid HelmConfig. 33 func TestNewHelmConfig(t *testing.T) { 34 defer helmCleanUp() 35 helmConfig := getHelmConfig(t) 36 assert.Equal(t, testRepoConfig, helmConfig.settings.RepositoryConfig) 37 assert.Equal(t, testRepoCache, helmConfig.settings.RepositoryCache) 38 assert.NotNil(t, helmConfig.helmRepoFile) 39 } 40 41 func getHelmConfig(t *testing.T) *VerrazzanoHelmConfig { 42 os.Setenv(envVarRepoConfig, testRepoConfig) 43 os.Setenv(envVarRepoCache, testRepoCache) 44 rc, cleanup, err := vcmtesthelpers.ContextSetup() 45 assert.NoError(t, err) 46 defer cleanup() 47 helmConfig, err := NewHelmConfig(rc) 48 assert.NoError(t, err) 49 assert.NotNil(t, helmConfig) 50 return helmConfig 51 } 52 53 func helmCleanUp() { 54 os.Setenv(envVarRepoConfig, prevRepoConfig) 55 os.Setenv(envVarRepoCache, prevRepoCache) 56 }