Fix kubectl version unit test

Signed-off-by: Eddie Zaneski <eddiezane@gmail.com>
This commit is contained in:
Eddie Zaneski 2021-07-27 11:46:45 -06:00
parent d92b788faa
commit 93ef5acb35
No known key found for this signature in database
GPG Key ID: 6B264594A44BB3EF

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") {