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

This commit is contained in:
Brian Pursley 2020-02-03 12:17:51 -05:00
parent 48ee18b516
commit 97185e9752

View File

@ -107,7 +107,7 @@ func TestPluginPathsAreValid(t *testing.T) {
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",
@ -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 {