From d376a67ba86c719431310f7797530bb7b020ea81 Mon Sep 17 00:00:00 2001 From: yxxhero Date: Fri, 8 Oct 2021 22:40:04 +0800 Subject: [PATCH 1/2] add SetNamespace method for EnvSettings, in order to set namespace in helm sdk Signed-off-by: yxxhero --- pkg/cli/environment.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/cli/environment.go b/pkg/cli/environment.go index ee60d981f..7e3933cc6 100644 --- a/pkg/cli/environment.go +++ b/pkg/cli/environment.go @@ -180,6 +180,11 @@ func (s *EnvSettings) Namespace() string { return "default" } +// SetNamespace sets the namespace in the configuration +func (s *EnvSettings) SetNamespace(namespace string) { + s.namespace = namespace +} + // RESTClientGetter gets the kubeconfig from EnvSettings func (s *EnvSettings) RESTClientGetter() genericclioptions.RESTClientGetter { return s.config From 0d3289eb0b2db911d1b08d54833b4ddf127f6d25 Mon Sep 17 00:00:00 2001 From: yxxhero Date: Fri, 8 Oct 2021 23:02:29 +0800 Subject: [PATCH 2/2] add unittest for SetNamespace method Signed-off-by: yxxhero --- pkg/cli/environment_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pkg/cli/environment_test.go b/pkg/cli/environment_test.go index 31ba7a237..1c3dc815e 100644 --- a/pkg/cli/environment_test.go +++ b/pkg/cli/environment_test.go @@ -25,6 +25,20 @@ import ( "github.com/spf13/pflag" ) +func TestSetNamespace(t *testing.T) { + settings := New() + + if settings.namespace != "" { + t.Errorf("Expected empty namespace, got %s", settings.namespace) + } + + settings.SetNamespace("testns") + if settings.namespace != "testns" { + t.Errorf("Expected namespace testns, got %s", settings.namespace) + } + +} + func TestEnvSettings(t *testing.T) { tests := []struct { name string