Skip to content

Commit 3486577

Browse files
committed
Fix kubectl version test to tolerate Run error coming from default
localhost:8080
1 parent a871738 commit 3486577

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

staging/src/k8s.io/kubectl/pkg/cmd/version/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ go_test(
2727
deps = [
2828
"//staging/src/k8s.io/cli-runtime/pkg/genericclioptions:go_default_library",
2929
"//staging/src/k8s.io/kubectl/pkg/cmd/util:go_default_library",
30+
"//vendor/github.com/spf13/cobra:go_default_library",
3031
],
3132
)
3233

staging/src/k8s.io/kubectl/pkg/cmd/version/version_test.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,26 @@ import (
2020
"strings"
2121
"testing"
2222

23+
"github.com/spf13/cobra"
24+
2325
"k8s.io/cli-runtime/pkg/genericclioptions"
2426
cmdutil "k8s.io/kubectl/pkg/cmd/util"
2527
)
2628

2729
func TestNewCmdVersionWithoutConfigFile(t *testing.T) {
2830
tf := cmdutil.NewFactory(&genericclioptions.ConfigFlags{})
2931
streams, _, buf, _ := genericclioptions.NewTestIOStreams()
30-
cmd := NewCmdVersion(tf, streams)
31-
cmd.SetOutput(buf)
32-
if err := cmd.Execute(); err != nil {
32+
o := NewOptions(streams)
33+
if err := o.Complete(tf, &cobra.Command{}); err != nil {
34+
t.Errorf("Unexpected error: %v", err)
35+
}
36+
if err := o.Validate(); err != nil {
37+
t.Errorf("Unexpected error: %v", err)
38+
}
39+
// FIXME soltysh:
40+
// since we have defaulting to localhost:8080 in staging/src/k8s.io/client-go/tools/clientcmd/client_config.go#getDefaultServer
41+
// we need to ignore the localhost:8080 server, when above gets removed this should be dropped too
42+
if err := o.Run(); err != nil && !strings.Contains(err.Error(), "localhost:8080") {
3343
t.Errorf("Cannot execute version command: %v", err)
3444
}
3545
if !strings.Contains(buf.String(), "Client Version") {

0 commit comments

Comments
 (0)