sigs.k8s.io/cluster-api-provider-azure@v1.14.3/util/system/namespace_test.go (about) 1 /* 2 Copyright 2021 The Kubernetes 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 system 18 19 import ( 20 "os" 21 "testing" 22 23 "github.com/onsi/gomega" 24 ) 25 26 func TestGetNamespace(t *testing.T) { 27 cases := []struct { 28 Name string 29 PodNamespace string 30 Expected string 31 }{ 32 { 33 Name: "env var set to custom namespace", 34 PodNamespace: "capz", 35 Expected: "capz", 36 }, 37 { 38 Name: "env var empty", 39 PodNamespace: "", 40 Expected: "capz-system", 41 }, 42 } 43 44 for _, c := range cases { 45 c := c 46 t.Run(c.Name, func(t *testing.T) { 47 g := gomega.NewWithT(t) 48 os.Setenv(NamespaceEnvVarName, c.PodNamespace) 49 defer os.Unsetenv(NamespaceEnvVarName) 50 g.Expect(GetManagerNamespace()).To(gomega.Equal(c.Expected)) 51 }) 52 } 53 }