From 46880f076bea651ec1be0da9aee46475c8f5e140 Mon Sep 17 00:00:00 2001 From: Dan Lorenc Date: Tue, 8 Sep 2020 13:05:59 -0500 Subject: [PATCH] Remove pkg/system. This is almost identical to the code in knative/pkg/system which we already import and use in a few cases. --- cmd/webhook/main.go | 4 +- pkg/pod/pod_test.go | 29 +++++------ .../pipelinerun/affinity_assistant_test.go | 9 ++-- .../pipelinerun/pipelinerun_test.go | 15 +++--- pkg/reconciler/taskrun/taskrun_test.go | 23 ++++----- pkg/system/names.go | 33 ------------- pkg/system/names_test.go | 48 ------------------- 7 files changed, 42 insertions(+), 119 deletions(-) delete mode 100644 pkg/system/names.go delete mode 100644 pkg/system/names_test.go diff --git a/cmd/webhook/main.go b/cmd/webhook/main.go index 4737b7addeb..6b40427c99d 100644 --- a/cmd/webhook/main.go +++ b/cmd/webhook/main.go @@ -25,7 +25,6 @@ import ( "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" "github.com/tektoncd/pipeline/pkg/contexts" - "github.com/tektoncd/pipeline/pkg/system" "k8s.io/apimachinery/pkg/runtime/schema" "knative.dev/pkg/configmap" "knative.dev/pkg/controller" @@ -34,6 +33,7 @@ import ( pkgleaderelection "knative.dev/pkg/leaderelection" "knative.dev/pkg/logging" "knative.dev/pkg/signals" + "knative.dev/pkg/system" "knative.dev/pkg/webhook" "knative.dev/pkg/webhook/certificates" "knative.dev/pkg/webhook/configmaps" @@ -204,7 +204,7 @@ func main() { } // Scope informers to the webhook's namespace instead of cluster-wide - ctx := injection.WithNamespaceScope(signals.NewContext(), system.GetNamespace()) + ctx := injection.WithNamespaceScope(signals.NewContext(), system.Namespace()) // Set up a signal context with our webhook options ctx = webhook.WithOptions(ctx, webhook.Options{ diff --git a/pkg/pod/pod_test.go b/pkg/pod/pod_test.go index 3914beb25ad..77987343de2 100644 --- a/pkg/pod/pod_test.go +++ b/pkg/pod/pod_test.go @@ -29,7 +29,6 @@ import ( "github.com/tektoncd/pipeline/pkg/apis/pipeline" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - "github.com/tektoncd/pipeline/pkg/system" "github.com/tektoncd/pipeline/test/diff" "github.com/tektoncd/pipeline/test/names" corev1 "k8s.io/api/core/v1" @@ -37,6 +36,8 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" fakek8s "k8s.io/client-go/kubernetes/fake" logtesting "knative.dev/pkg/logging/testing" + "knative.dev/pkg/system" + _ "knative.dev/pkg/system/testing" ) var ( @@ -1091,7 +1092,7 @@ script-heredoc-randomly-generated-78c5n store := config.NewStore(logtesting.TestLogger(t)) store.OnConfigChanged( &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.Namespace()}, Data: c.featureFlags, }, ) @@ -1197,14 +1198,14 @@ func TestShouldOverrideHomeEnv(t *testing.T) { }{{ description: "Default behaviour: A missing disable-home-env-overwrite flag should result in true", configMap: &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{}, }, expected: true, }, { description: "Setting disable-home-env-overwrite to false should result in true", configMap: &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{ featureFlagDisableHomeEnvKey: "false", }, @@ -1213,7 +1214,7 @@ func TestShouldOverrideHomeEnv(t *testing.T) { }, { description: "Setting disable-home-env-overwrite to true should result in false", configMap: &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{ featureFlagDisableHomeEnvKey: "true", }, @@ -1238,14 +1239,14 @@ func TestShouldOverrideWorkingDir(t *testing.T) { }{{ description: "Default behaviour: A missing disable-working-directory-overwrite flag should result in true", configMap: &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{}, }, expected: true, }, { description: "Setting disable-working-directory-overwrite to false should result in true", configMap: &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{ featureFlagDisableWorkingDirKey: "false", }, @@ -1254,7 +1255,7 @@ func TestShouldOverrideWorkingDir(t *testing.T) { }, { description: "Setting disable-working-directory-overwrite to true should result in false", configMap: &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{ featureFlagDisableWorkingDirKey: "true", }, @@ -1287,7 +1288,7 @@ func TestShouldAddReadyAnnotationonPodCreate(t *testing.T) { description: "Default behavior with sidecars present: Ready annotation not set on pod create", sidecars: []v1beta1.Sidecar{sd}, configMap: &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{}, }, expected: false, @@ -1295,7 +1296,7 @@ func TestShouldAddReadyAnnotationonPodCreate(t *testing.T) { description: "Default behavior with no sidecars present: Ready annotation not set on pod create", sidecars: []v1beta1.Sidecar{}, configMap: &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{}, }, expected: false, @@ -1303,7 +1304,7 @@ func TestShouldAddReadyAnnotationonPodCreate(t *testing.T) { description: "Setting running-in-environment-with-injected-sidecars to true with sidecars present results in false", sidecars: []v1beta1.Sidecar{sd}, configMap: &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{ featureInjectedSidecar: "true", }, @@ -1313,7 +1314,7 @@ func TestShouldAddReadyAnnotationonPodCreate(t *testing.T) { description: "Setting running-in-environment-with-injected-sidecars to true with no sidecars present results in false", sidecars: []v1beta1.Sidecar{}, configMap: &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{ featureInjectedSidecar: "true", }, @@ -1323,7 +1324,7 @@ func TestShouldAddReadyAnnotationonPodCreate(t *testing.T) { description: "Setting running-in-environment-with-injected-sidecars to false with sidecars present results in false", sidecars: []v1beta1.Sidecar{sd}, configMap: &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{ featureInjectedSidecar: "false", }, @@ -1333,7 +1334,7 @@ func TestShouldAddReadyAnnotationonPodCreate(t *testing.T) { description: "Setting running-in-environment-with-injected-sidecars to false with no sidecars present results in true", sidecars: []v1beta1.Sidecar{}, configMap: &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{ featureInjectedSidecar: "false", }, diff --git a/pkg/reconciler/pipelinerun/affinity_assistant_test.go b/pkg/reconciler/pipelinerun/affinity_assistant_test.go index 82af7a1dadc..ba853c94859 100644 --- a/pkg/reconciler/pipelinerun/affinity_assistant_test.go +++ b/pkg/reconciler/pipelinerun/affinity_assistant_test.go @@ -23,12 +23,13 @@ import ( "github.com/tektoncd/pipeline/pkg/apis/config" "github.com/tektoncd/pipeline/pkg/apis/pipeline" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - "github.com/tektoncd/pipeline/pkg/system" corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" fakek8s "k8s.io/client-go/kubernetes/fake" logtesting "knative.dev/pkg/logging/testing" + "knative.dev/pkg/system" + _ "knative.dev/pkg/system/testing" ) // TestCreateAndDeleteOfAffinityAssistant tests to create and delete an Affinity Assistant @@ -154,14 +155,14 @@ func TestDisableAffinityAssistant(t *testing.T) { }{{ description: "Default behaviour: A missing disable-affinity-assistant flag should result in false", configMap: &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{}, }, expected: false, }, { description: "Setting disable-affinity-assistant to false should result in false", configMap: &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{ featureFlagDisableAffinityAssistantKey: "false", }, @@ -170,7 +171,7 @@ func TestDisableAffinityAssistant(t *testing.T) { }, { description: "Setting disable-affinity-assistant to true should result in true", configMap: &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{ featureFlagDisableAffinityAssistantKey: "true", }, diff --git a/pkg/reconciler/pipelinerun/pipelinerun_test.go b/pkg/reconciler/pipelinerun/pipelinerun_test.go index 25ccb7e1a54..3ae29a58e1f 100644 --- a/pkg/reconciler/pipelinerun/pipelinerun_test.go +++ b/pkg/reconciler/pipelinerun/pipelinerun_test.go @@ -37,7 +37,6 @@ import ( "github.com/tektoncd/pipeline/pkg/reconciler/pipelinerun/resources" taskrunresources "github.com/tektoncd/pipeline/pkg/reconciler/taskrun/resources" ttesting "github.com/tektoncd/pipeline/pkg/reconciler/testing" - "github.com/tektoncd/pipeline/pkg/system" "github.com/tektoncd/pipeline/test" "github.com/tektoncd/pipeline/test/diff" "github.com/tektoncd/pipeline/test/names" @@ -57,6 +56,8 @@ import ( "knative.dev/pkg/controller" "knative.dev/pkg/logging" "knative.dev/pkg/reconciler" + "knative.dev/pkg/system" + _ "knative.dev/pkg/system/testing" ) var ( @@ -103,25 +104,25 @@ func ensureConfigurationConfigMapsExist(d *test.Data) { } if !defaultsExists { d.ConfigMaps = append(d.ConfigMaps, &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetDefaultsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetDefaultsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{}, }) } if !featureFlagsExists { d.ConfigMaps = append(d.ConfigMaps, &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{}, }) } if !artifactBucketExists { d.ConfigMaps = append(d.ConfigMaps, &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetArtifactBucketConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetArtifactBucketConfigName(), Namespace: system.Namespace()}, Data: map[string]string{}, }) } if !artifactPVCExists { d.ConfigMaps = append(d.ConfigMaps, &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetArtifactPVCConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetArtifactPVCConfigName(), Namespace: system.Namespace()}, Data: map[string]string{}, }) } @@ -135,7 +136,7 @@ func getPipelineRunController(t *testing.T, d test.Data) (test.Assets, func()) { ctx, cancel := context.WithCancel(ctx) ensureConfigurationConfigMapsExist(&d) c, informers := test.SeedTestData(t, ctx, d) - configMapWatcher := configmap.NewInformedWatcher(c.Kube, system.GetNamespace()) + configMapWatcher := configmap.NewInformedWatcher(c.Kube, system.Namespace()) ctl := NewController(namespace, images)(ctx, configMapWatcher) @@ -3758,7 +3759,7 @@ func TestReconcile_CloudEvents(t *testing.T) { } cms := []*corev1.ConfigMap{ { - ObjectMeta: metav1.ObjectMeta{Name: config.GetDefaultsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetDefaultsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{ "default-cloud-events-sink": "http://synk:8080", }, diff --git a/pkg/reconciler/taskrun/taskrun_test.go b/pkg/reconciler/taskrun/taskrun_test.go index 9f6897fd2c2..758a76eb329 100644 --- a/pkg/reconciler/taskrun/taskrun_test.go +++ b/pkg/reconciler/taskrun/taskrun_test.go @@ -36,7 +36,6 @@ import ( "github.com/tektoncd/pipeline/pkg/reconciler/events/cloudevent" ttesting "github.com/tektoncd/pipeline/pkg/reconciler/testing" "github.com/tektoncd/pipeline/pkg/reconciler/volumeclaim" - "github.com/tektoncd/pipeline/pkg/system" "github.com/tektoncd/pipeline/pkg/timeout" "github.com/tektoncd/pipeline/pkg/workspace" test "github.com/tektoncd/pipeline/test" @@ -58,6 +57,8 @@ import ( "knative.dev/pkg/controller" "knative.dev/pkg/logging" pkgreconciler "knative.dev/pkg/reconciler" + "knative.dev/pkg/system" + _ "knative.dev/pkg/system/testing" ) const ( @@ -252,25 +253,25 @@ func ensureConfigurationConfigMapsExist(d *test.Data) { } if !defaultsExists { d.ConfigMaps = append(d.ConfigMaps, &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetDefaultsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetDefaultsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{}, }) } if !featureFlagsExists { d.ConfigMaps = append(d.ConfigMaps, &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{}, }) } if !artifactBucketExists { d.ConfigMaps = append(d.ConfigMaps, &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetArtifactBucketConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetArtifactBucketConfigName(), Namespace: system.Namespace()}, Data: map[string]string{}, }) } if !artifactPVCExists { d.ConfigMaps = append(d.ConfigMaps, &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetArtifactPVCConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetArtifactPVCConfigName(), Namespace: system.Namespace()}, Data: map[string]string{}, }) } @@ -284,7 +285,7 @@ func getTaskRunController(t *testing.T, d test.Data) (test.Assets, func()) { ctx, cancel := context.WithCancel(ctx) ensureConfigurationConfigMapsExist(&d) c, informers := test.SeedTestData(t, ctx, d) - configMapWatcher := configmap.NewInformedWatcher(c.Kube, system.GetNamespace()) + configMapWatcher := configmap.NewInformedWatcher(c.Kube, system.Namespace()) ctl := NewController(namespace, images)(ctx, configMapWatcher) if err := configMapWatcher.Start(ctx.Done()); err != nil { @@ -365,7 +366,7 @@ func TestReconcile_ExplicitDefaultSA(t *testing.T) { Tasks: []*v1beta1.Task{simpleTask, saTask}, ConfigMaps: []*corev1.ConfigMap{ { - ObjectMeta: metav1.ObjectMeta{Name: config.GetDefaultsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetDefaultsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{ "default-service-account": defaultSAName, "default-timeout-minutes": "60", @@ -648,7 +649,7 @@ func TestReconcile_FeatureFlags(t *testing.T) { names.TestingSeed() d.ConfigMaps = []*corev1.ConfigMap{ { - ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetFeatureFlagsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{ tc.featureFlag: "true", }, @@ -734,7 +735,7 @@ func TestReconcile_CloudEvents(t *testing.T) { names.TestingSeed() d.ConfigMaps = []*corev1.ConfigMap{ { - ObjectMeta: metav1.ObjectMeta{Name: config.GetDefaultsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetDefaultsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{ "default-cloud-events-sink": "http://synk:8080", }, @@ -2770,7 +2771,7 @@ func TestReconcileValidDefaultWorkspace(t *testing.T) { } d.ConfigMaps = append(d.ConfigMaps, &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetDefaultsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetDefaultsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{ "default-task-run-workspace-binding": "emptyDir: {}", }, @@ -2826,7 +2827,7 @@ func TestReconcileInvalidDefaultWorkspace(t *testing.T) { } d.ConfigMaps = append(d.ConfigMaps, &corev1.ConfigMap{ - ObjectMeta: metav1.ObjectMeta{Name: config.GetDefaultsConfigName(), Namespace: system.GetNamespace()}, + ObjectMeta: metav1.ObjectMeta{Name: config.GetDefaultsConfigName(), Namespace: system.Namespace()}, Data: map[string]string{ "default-task-run-workspace-binding": "emptyDir == {}", }, diff --git a/pkg/system/names.go b/pkg/system/names.go deleted file mode 100644 index f4c31a2867f..00000000000 --- a/pkg/system/names.go +++ /dev/null @@ -1,33 +0,0 @@ -/* -Copyright 2019 The Tekton Authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package system - -import "os" - -const ( - DefaultNamespace = "tekton-pipelines" - SystemNamespaceEnvVar = "SYSTEM_NAMESPACE" -) - -// GetNamespace holds the K8s namespace where our system components run. -func GetNamespace() string { - systemNamespace := os.Getenv(SystemNamespaceEnvVar) - if systemNamespace == "" { - return DefaultNamespace - } - return systemNamespace -} diff --git a/pkg/system/names_test.go b/pkg/system/names_test.go deleted file mode 100644 index dbc14345a91..00000000000 --- a/pkg/system/names_test.go +++ /dev/null @@ -1,48 +0,0 @@ -/* -Copyright 2019 The Tekton Authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package system - -import ( - "os" - "testing" -) - -func TestGetNamespace(t *testing.T) { - testcases := []struct { - envVar string - expectEnvVar string - }{{ - envVar: "", - expectEnvVar: DefaultNamespace, - }, { - envVar: "test", - expectEnvVar: "test", - }} - - value := os.Getenv(SystemNamespaceEnvVar) - defer func() { os.Setenv(SystemNamespaceEnvVar, value) }() - - for _, ts := range testcases { - if err := os.Setenv(SystemNamespaceEnvVar, ts.envVar); err != nil { - t.Fatalf("Failed to set ENV: %v", err) - } - - if got, want := GetNamespace(), ts.expectEnvVar; got != want { - t.Fatalf("Invalid namespace: got: %v, want: %v", got, want) - } - } -}