|
| 1 | +/* |
| 2 | +Copyright 2026 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 env |
| 18 | + |
| 19 | +import ( |
| 20 | + "testing" |
| 21 | + |
| 22 | + "k8s.io/kops/pkg/apis/kops" |
| 23 | + "k8s.io/kops/upup/pkg/fi" |
| 24 | +) |
| 25 | + |
| 26 | +func TestBuildSystemComponentEnvVars(t *testing.T) { |
| 27 | + tests := []struct { |
| 28 | + name string |
| 29 | + spec *kops.ClusterSpec |
| 30 | + envVar string |
| 31 | + wantVal string |
| 32 | + wantExist bool |
| 33 | + }{ |
| 34 | + { |
| 35 | + name: "Openstack nil", |
| 36 | + spec: &kops.ClusterSpec{ |
| 37 | + CloudProvider: kops.CloudProviderSpec{}, |
| 38 | + }, |
| 39 | + envVar: "KOPS_OS_TLS_INSECURE_SKIP_VERIFY", |
| 40 | + wantExist: false, |
| 41 | + }, |
| 42 | + { |
| 43 | + name: "Openstack InsecureSkipVerify nil", |
| 44 | + spec: &kops.ClusterSpec{ |
| 45 | + CloudProvider: kops.CloudProviderSpec{ |
| 46 | + Openstack: &kops.OpenstackSpec{}, |
| 47 | + }, |
| 48 | + }, |
| 49 | + envVar: "KOPS_OS_TLS_INSECURE_SKIP_VERIFY", |
| 50 | + wantExist: false, |
| 51 | + }, |
| 52 | + { |
| 53 | + name: "Openstack InsecureSkipVerify false", |
| 54 | + spec: &kops.ClusterSpec{ |
| 55 | + CloudProvider: kops.CloudProviderSpec{ |
| 56 | + Openstack: &kops.OpenstackSpec{ |
| 57 | + InsecureSkipVerify: fi.PtrTo(false), |
| 58 | + }, |
| 59 | + }, |
| 60 | + }, |
| 61 | + envVar: "KOPS_OS_TLS_INSECURE_SKIP_VERIFY", |
| 62 | + wantExist: false, |
| 63 | + }, |
| 64 | + { |
| 65 | + name: "Openstack InsecureSkipVerify true", |
| 66 | + spec: &kops.ClusterSpec{ |
| 67 | + CloudProvider: kops.CloudProviderSpec{ |
| 68 | + Openstack: &kops.OpenstackSpec{ |
| 69 | + InsecureSkipVerify: fi.PtrTo(true), |
| 70 | + }, |
| 71 | + }, |
| 72 | + }, |
| 73 | + envVar: "KOPS_OS_TLS_INSECURE_SKIP_VERIFY", |
| 74 | + wantVal: "true", |
| 75 | + wantExist: true, |
| 76 | + }, |
| 77 | + } |
| 78 | + |
| 79 | + for _, tc := range tests { |
| 80 | + t.Run(tc.name, func(t *testing.T) { |
| 81 | + vars := BuildSystemComponentEnvVars(tc.spec) |
| 82 | + val, ok := vars[tc.envVar] |
| 83 | + if ok != tc.wantExist { |
| 84 | + t.Errorf("Expected existence of key %q to be %v, but got %v", tc.envVar, tc.wantExist, ok) |
| 85 | + } |
| 86 | + if tc.wantExist && val != tc.wantVal { |
| 87 | + t.Errorf("Expected value of key %q to be %q, but got %q", tc.envVar, tc.wantVal, val) |
| 88 | + } |
| 89 | + }) |
| 90 | + } |
| 91 | +} |
0 commit comments