Merge pull request #103955 from eddiezane/ez/fix-kubectl-version-test

Fix kubectl version unit test
This commit is contained in:
Kubernetes Prow Robot
2021-08-08 18:15:30 -07:00
committed by GitHub

View File

@@ -23,11 +23,12 @@ import (
"github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
cmdtesting "k8s.io/kubectl/pkg/cmd/testing"
)
func TestNewCmdVersionWithoutConfigFile(t *testing.T) {
tf := cmdutil.NewFactory(&genericclioptions.ConfigFlags{})
func TestNewCmdVersionClientVersion(t *testing.T) {
tf := cmdtesting.NewTestFactory().WithNamespace("test")
defer tf.Cleanup()
streams, _, buf, _ := genericclioptions.NewTestIOStreams()
o := NewOptions(streams)
if err := o.Complete(tf, &cobra.Command{}); err != nil {
@@ -36,10 +37,7 @@ func TestNewCmdVersionWithoutConfigFile(t *testing.T) {
if err := o.Validate(); err != nil {
t.Errorf("Unexpected error: %v", err)
}
// FIXME soltysh:
// since we have defaulting to localhost:8080 in staging/src/k8s.io/client-go/tools/clientcmd/client_config.go#getDefaultServer
// we need to ignore the localhost:8080 server, when above gets removed this should be dropped too
if err := o.Run(); err != nil && !strings.Contains(err.Error(), "localhost:8080") {
if err := o.Run(); err != nil {
t.Errorf("Cannot execute version command: %v", err)
}
if !strings.Contains(buf.String(), "Client Version") {