Skip to content

Commit

Permalink
Add test create service with ns
Browse files Browse the repository at this point in the history
  • Loading branch information
zxh326 authored and eddiezane committed May 6, 2021
1 parent 0f2adad commit 61e6599
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions staging/src/k8s.io/kubectl/pkg/cmd/create/create_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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())
}
}

0 comments on commit 61e6599

Please sign in to comment.