github.com/openebs/node-disk-manager@v1.9.1-0.20230225014141-4531f06ffa1e/pkg/env/env_test.go (about) 1 /* 2 Copyright 2020 The OpenEBS Authors 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package env 18 19 import ( 20 "os" 21 "testing" 22 23 v1 "k8s.io/api/core/v1" 24 25 "github.com/stretchr/testify/assert" 26 ) 27 28 func TestGetOpenEBSImagePullSecrets(t *testing.T) { 29 tests := map[string]struct { 30 envValue string 31 secret []v1.LocalObjectReference 32 }{ 33 "empty variable": { 34 envValue: "", 35 secret: []v1.LocalObjectReference{}, 36 }, 37 "single value": { 38 envValue: "image-pull-secret", 39 secret: []v1.LocalObjectReference{{Name: "image-pull-secret"}}, 40 }, 41 "multiple value": { 42 envValue: "image-pull-secret,secret-1", 43 secret: []v1.LocalObjectReference{{Name: "image-pull-secret"}, {Name: "secret-1"}}, 44 }, 45 "whitespaces": { 46 envValue: " ", 47 secret: []v1.LocalObjectReference{}, 48 }, 49 "single value with whitespaces": { 50 envValue: " docker-secret ", 51 secret: []v1.LocalObjectReference{{Name: "docker-secret"}}, 52 }, 53 "multiple value with whitespaces": { 54 envValue: " docker-secret, image-pull-secret ", 55 secret: []v1.LocalObjectReference{{Name: "docker-secret"}, {Name: "image-pull-secret"}}, 56 }, 57 } 58 for name, tt := range tests { 59 t.Run(name, func(t *testing.T) { 60 os.Setenv(IMAGE_PULL_SECRETS_ENV, tt.envValue) 61 got := GetOpenEBSImagePullSecrets() 62 assert.Equal(t, tt.secret, got) 63 os.Unsetenv(IMAGE_PULL_SECRETS_ENV) 64 }) 65 } 66 }