Fixed problem in unit test where error expected/actual comparison was not being performed

Kubernetes-commit: 97185e97529ef7c006f26bb3190805ad28f15ffe
This commit is contained in:
Brian Pursley 2020-02-03 12:17:51 -05:00 committed by Kubernetes Publisher
parent b69c2a4389
commit e9f1eb93f4
1 changed files with 20 additions and 21 deletions

View File

@ -101,31 +101,31 @@ func TestPluginPathsAreValid(t *testing.T) {
expectOut string expectOut string
}{ }{
{ {
name: "ensure no plugins found if no files begin with kubectl- prefix", name: "ensure no plugins found if no files begin with kubectl- prefix",
pluginPaths: []string{tempDir}, pluginPaths: []string{tempDir},
verifier: newFakePluginPathVerifier(), verifier: newFakePluginPathVerifier(),
pluginFile: func() (*os.File, error) { pluginFile: func() (*os.File, error) {
return ioutil.TempFile(tempDir, "notkubectl-") return ioutil.TempFile(tempDir, "notkubectl-")
}, },
expectErr: "unable to find any kubectl plugins in your PATH", expectErr: "error: unable to find any kubectl plugins in your PATH\n",
}, },
{ {
name: "ensure de-duplicated plugin-paths slice", name: "ensure de-duplicated plugin-paths slice",
pluginPaths: []string{tempDir, tempDir}, pluginPaths: []string{tempDir, tempDir},
verifier: newFakePluginPathVerifier(), verifier: newFakePluginPathVerifier(),
pluginFile: func() (*os.File, error) { pluginFile: func() (*os.File, error) {
return ioutil.TempFile(tempDir, "kubectl-") return ioutil.TempFile(tempDir, "kubectl-")
}, },
expectOut: "The following compatible plugins are available:", expectOut: "The following compatible plugins are available:",
}, },
{ {
name: "ensure no errors when empty string or blank path are specified", name: "ensure no errors when empty string or blank path are specified",
pluginPaths: []string{tempDir, "", " "}, pluginPaths: []string{tempDir, "", " "},
verifier: newFakePluginPathVerifier(), verifier: newFakePluginPathVerifier(),
pluginFile: func() (*os.File, error) { pluginFile: func() (*os.File, error) {
return ioutil.TempFile(tempDir, "kubectl-") return ioutil.TempFile(tempDir, "kubectl-")
}, },
expectOut: "The following compatible plugins are available:", expectOut: "The following compatible plugins are available:",
}, },
} }
@ -138,8 +138,6 @@ func TestPluginPathsAreValid(t *testing.T) {
PluginPaths: test.pluginPaths, PluginPaths: test.pluginPaths,
} }
o.Out = out
o.ErrOut = errOut
// create files // create files
if test.pluginFile != nil { if test.pluginFile != nil {
@ -158,10 +156,11 @@ func TestPluginPathsAreValid(t *testing.T) {
err := o.Run() err := o.Run()
if err == nil && len(test.expectErr) > 0 { if err == nil && len(test.expectErr) > 0 {
t.Fatalf("unexpected non-error: expecting %v", test.expectErr) t.Fatalf("unexpected non-error: expected %v, but got nothing", test.expectErr)
} } else if err != nil && len(test.expectErr) == 0 {
if err != nil && len(test.expectErr) == 0 { t.Fatalf("unexpected error: expected nothing, but got %v", err.Error())
t.Fatalf("unexpected error: %v - %v", err, errOut.String()) } else if err != nil && err.Error() != test.expectErr {
t.Fatalf("unexpected error: expected %v, but got %v", test.expectErr, err.Error())
} }
if len(test.expectErrOut) == 0 && errOut.Len() > 0 { if len(test.expectErrOut) == 0 && errOut.Len() > 0 {