Add test create service with ns

Kubernetes-commit: 84b9159a2e7e20b143d5756bf7f9ccb36d58926a
This commit is contained in:
Zzde 2021-04-22 17:39:23 +08:00 committed by Kubernetes Publisher
parent dd3b5db48b
commit 161f78e312
1 changed files with 22 additions and 0 deletions

View File

@ -17,6 +17,9 @@ limitations under the License.
package create package create
import ( import (
"k8s.io/cli-runtime/pkg/genericclioptions"
restclient "k8s.io/client-go/rest"
cmdtesting "k8s.io/kubectl/pkg/cmd/testing"
"testing" "testing"
v1 "k8s.io/api/core/v1" 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())
}
}