From d4e89547f065ac5eee67ab4646fb3cee874dc1a9 Mon Sep 17 00:00:00 2001 From: Jan Chaloupka Date: Fri, 20 Nov 2020 19:09:54 +0100 Subject: [PATCH] kubectl/pkg/cmd tests: set explicit namespace Otherwise, the namespace gets set to what's a current namespace in provided kubeconfig. Which can be different from default. --- .../kubectl/pkg/cmd/debug/debug_test.go | 32 +++++++++---------- .../k8s.io/kubectl/pkg/cmd/run/run_test.go | 6 ++-- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/staging/src/k8s.io/kubectl/pkg/cmd/debug/debug_test.go b/staging/src/k8s.io/kubectl/pkg/cmd/debug/debug_test.go index 84b26cad8a28..e4e5b6f5b6bd 100644 --- a/staging/src/k8s.io/kubectl/pkg/cmd/debug/debug_test.go +++ b/staging/src/k8s.io/kubectl/pkg/cmd/debug/debug_test.go @@ -1178,7 +1178,7 @@ func TestGenerateNodeDebugPod(t *testing.T) { } func TestCompleteAndValidate(t *testing.T) { - tf := cmdtesting.NewTestFactory() + tf := cmdtesting.NewTestFactory().WithNamespace("test") ioStreams, _, _, _ := genericclioptions.NewTestIOStreams() cmpFilter := cmp.FilterPath(func(p cmp.Path) bool { switch p.String() { @@ -1225,7 +1225,7 @@ func TestCompleteAndValidate(t *testing.T) { wantOpts: &DebugOptions{ Args: []string{}, Image: "busybox", - Namespace: "default", + Namespace: "test", PullPolicy: corev1.PullPolicy("Always"), ShareProcesses: true, TargetNames: []string{"mypod"}, @@ -1237,7 +1237,7 @@ func TestCompleteAndValidate(t *testing.T) { wantOpts: &DebugOptions{ Args: []string{}, Image: "busybox", - Namespace: "default", + Namespace: "test", ShareProcesses: true, TargetNames: []string{"mypod1", "mypod2"}, }, @@ -1248,7 +1248,7 @@ func TestCompleteAndValidate(t *testing.T) { wantOpts: &DebugOptions{ Args: []string{"echo", "1", "2"}, Image: "busybox", - Namespace: "default", + Namespace: "test", ShareProcesses: true, TargetNames: []string{"mypod1", "mypod2"}, }, @@ -1261,7 +1261,7 @@ func TestCompleteAndValidate(t *testing.T) { Attach: false, Image: "busybox", Interactive: true, - Namespace: "default", + Namespace: "test", ShareProcesses: true, TargetNames: []string{"mypod"}, TTY: true, @@ -1274,7 +1274,7 @@ func TestCompleteAndValidate(t *testing.T) { Args: []string{}, Env: []v1.EnvVar{{Name: "FOO", Value: "BAR"}}, Image: "busybox", - Namespace: "default", + Namespace: "test", ShareProcesses: true, TargetNames: []string{"mypod"}, }, @@ -1287,7 +1287,7 @@ func TestCompleteAndValidate(t *testing.T) { Attach: true, Image: "busybox", Interactive: true, - Namespace: "default", + Namespace: "test", ShareProcesses: true, TargetNames: []string{"mypod"}, TTY: true, @@ -1300,7 +1300,7 @@ func TestCompleteAndValidate(t *testing.T) { Args: []string{}, Container: "debugger", Image: "myproj/debug-tools", - Namespace: "default", + Namespace: "test", PullPolicy: corev1.PullPolicy("Always"), ShareProcesses: true, TargetNames: []string{"mypod"}, @@ -1340,7 +1340,7 @@ func TestCompleteAndValidate(t *testing.T) { CopyTo: "my-debugger", Image: "busybox", Interactive: true, - Namespace: "default", + Namespace: "test", ShareProcesses: true, TargetNames: []string{"mypod"}, TTY: true, @@ -1354,7 +1354,7 @@ func TestCompleteAndValidate(t *testing.T) { Container: "my-container", CopyTo: "my-debugger", Image: "busybox", - Namespace: "default", + Namespace: "test", ShareProcesses: true, TargetNames: []string{"mypod"}, }, @@ -1367,7 +1367,7 @@ func TestCompleteAndValidate(t *testing.T) { Attach: true, CopyTo: "my-debugger", Image: "busybox", - Namespace: "default", + Namespace: "test", ShareProcesses: true, TargetNames: []string{"mypod"}, }, @@ -1380,7 +1380,7 @@ func TestCompleteAndValidate(t *testing.T) { Container: "my-container", CopyTo: "my-debugger", Image: "busybox", - Namespace: "default", + Namespace: "test", ShareProcesses: true, TargetNames: []string{"mypod"}, }, @@ -1391,7 +1391,7 @@ func TestCompleteAndValidate(t *testing.T) { wantOpts: &DebugOptions{ Args: []string{}, CopyTo: "my-debugger", - Namespace: "default", + Namespace: "test", SetImages: map[string]string{ "*": "busybox", "app": "app-debugger", @@ -1409,7 +1409,7 @@ func TestCompleteAndValidate(t *testing.T) { CopyTo: "my-debugger", Image: "debian", Interactive: true, - Namespace: "default", + Namespace: "test", SetImages: map[string]string{ "app": "app:debug", "sidecar": "sidecar:debug", @@ -1428,7 +1428,7 @@ func TestCompleteAndValidate(t *testing.T) { Container: "mycontainer", CopyTo: "my-debugger", Interactive: true, - Namespace: "default", + Namespace: "test", ShareProcesses: true, TargetNames: []string{"mypod"}, TTY: true, @@ -1467,7 +1467,7 @@ func TestCompleteAndValidate(t *testing.T) { Attach: true, Image: "busybox", Interactive: true, - Namespace: "default", + Namespace: "test", ShareProcesses: true, TargetNames: []string{"node/mynode"}, TTY: true, diff --git a/staging/src/k8s.io/kubectl/pkg/cmd/run/run_test.go b/staging/src/k8s.io/kubectl/pkg/cmd/run/run_test.go index d2a264fb6c5c..df1a5f0a5b1e 100644 --- a/staging/src/k8s.io/kubectl/pkg/cmd/run/run_test.go +++ b/staging/src/k8s.io/kubectl/pkg/cmd/run/run_test.go @@ -560,7 +560,7 @@ func TestExpose(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { - tf := cmdtesting.NewTestFactory() + tf := cmdtesting.NewTestFactory().WithNamespace("test") defer tf.Cleanup() codec := scheme.Codecs.LegacyCodec(scheme.Scheme.PrioritizedVersionsAllGroups()...) @@ -570,11 +570,11 @@ func TestExpose(t *testing.T) { Client: fake.CreateHTTPClient(func(req *http.Request) (*http.Response, error) { t.Logf("path: %v, method: %v", req.URL.Path, req.Method) switch p, m := req.URL.Path, req.Method; { - case m == "POST" && p == "/namespaces/default/pods": + case m == "POST" && p == "/namespaces/test/pods": pod := &corev1.Pod{} body := cmdtesting.ObjBody(codec, pod) return &http.Response{StatusCode: http.StatusOK, Header: cmdtesting.DefaultHeader(), Body: body}, nil - case m == "POST" && p == "/namespaces/default/services": + case m == "POST" && p == "/namespaces/test/services": data, err := ioutil.ReadAll(req.Body) if err != nil { t.Fatalf("unexpected error: %v", err)