From 61e659964b457ef4bb0653337ca4a247e656b77a Mon Sep 17 00:00:00 2001 From: Zzde Date: Thu, 22 Apr 2021 17:39:23 +0800 Subject: [PATCH] Add test create service with ns --- .../pkg/cmd/create/create_service_test.go | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/staging/src/k8s.io/kubectl/pkg/cmd/create/create_service_test.go b/staging/src/k8s.io/kubectl/pkg/cmd/create/create_service_test.go index 8365a116765c6..7249a68baa23c 100644 --- a/staging/src/k8s.io/kubectl/pkg/cmd/create/create_service_test.go +++ b/staging/src/k8s.io/kubectl/pkg/cmd/create/create_service_test.go @@ -17,6 +17,9 @@ limitations under the License. package create import ( + "k8s.io/cli-runtime/pkg/genericclioptions" + restclient "k8s.io/client-go/rest" + cmdtesting "k8s.io/kubectl/pkg/cmd/testing" "testing" v1 "k8s.io/api/core/v1" @@ -267,3 +270,22 @@ func TestCreateServices(t *testing.T) { }) } } + +func TestCreateServiceWithNamespace(t *testing.T) { + svcName := "test-service" + ns := "test" + tf := cmdtesting.NewTestFactory().WithNamespace(ns) + defer tf.Cleanup() + + tf.ClientConfigVal = &restclient.Config{} + + ioStreams, _, buf, _ := genericclioptions.NewTestIOStreams() + cmd := NewCmdCreateServiceClusterIP(tf, ioStreams) + cmd.Flags().Set("dry-run", "client") + cmd.Flags().Set("output", "jsonpath={.metadata.namespace}") + cmd.Flags().Set("clusterip", "None") + cmd.Run(cmd, []string{svcName}) + if buf.String() != ns { + t.Errorf("expected output: %s, but got: %s", ns, buf.String()) + } +}