Skip to content

Commit 97185e9

Browse files
committed
Fixed problem in unit test where error expected/actual comparison was not being performed
1 parent 48ee18b commit 97185e9

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

staging/src/k8s.io/kubectl/pkg/cmd/plugin/plugin_test.go

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -101,31 +101,31 @@ func TestPluginPathsAreValid(t *testing.T) {
101101
expectOut string
102102
}{
103103
{
104-
name: "ensure no plugins found if no files begin with kubectl- prefix",
105-
pluginPaths: []string{tempDir},
106-
verifier: newFakePluginPathVerifier(),
107-
pluginFile: func() (*os.File, error) {
104+
name: "ensure no plugins found if no files begin with kubectl- prefix",
105+
pluginPaths: []string{tempDir},
106+
verifier: newFakePluginPathVerifier(),
107+
pluginFile: func() (*os.File, error) {
108108
return ioutil.TempFile(tempDir, "notkubectl-")
109109
},
110-
expectErr: "unable to find any kubectl plugins in your PATH",
110+
expectErr: "error: unable to find any kubectl plugins in your PATH\n",
111111
},
112112
{
113-
name: "ensure de-duplicated plugin-paths slice",
114-
pluginPaths: []string{tempDir, tempDir},
115-
verifier: newFakePluginPathVerifier(),
116-
pluginFile: func() (*os.File, error) {
113+
name: "ensure de-duplicated plugin-paths slice",
114+
pluginPaths: []string{tempDir, tempDir},
115+
verifier: newFakePluginPathVerifier(),
116+
pluginFile: func() (*os.File, error) {
117117
return ioutil.TempFile(tempDir, "kubectl-")
118118
},
119-
expectOut: "The following compatible plugins are available:",
119+
expectOut: "The following compatible plugins are available:",
120120
},
121121
{
122-
name: "ensure no errors when empty string or blank path are specified",
123-
pluginPaths: []string{tempDir, "", " "},
124-
verifier: newFakePluginPathVerifier(),
125-
pluginFile: func() (*os.File, error) {
122+
name: "ensure no errors when empty string or blank path are specified",
123+
pluginPaths: []string{tempDir, "", " "},
124+
verifier: newFakePluginPathVerifier(),
125+
pluginFile: func() (*os.File, error) {
126126
return ioutil.TempFile(tempDir, "kubectl-")
127127
},
128-
expectOut: "The following compatible plugins are available:",
128+
expectOut: "The following compatible plugins are available:",
129129
},
130130
}
131131

@@ -138,8 +138,6 @@ func TestPluginPathsAreValid(t *testing.T) {
138138

139139
PluginPaths: test.pluginPaths,
140140
}
141-
o.Out = out
142-
o.ErrOut = errOut
143141

144142
// create files
145143
if test.pluginFile != nil {
@@ -158,10 +156,11 @@ func TestPluginPathsAreValid(t *testing.T) {
158156

159157
err := o.Run()
160158
if err == nil && len(test.expectErr) > 0 {
161-
t.Fatalf("unexpected non-error: expecting %v", test.expectErr)
162-
}
163-
if err != nil && len(test.expectErr) == 0 {
164-
t.Fatalf("unexpected error: %v - %v", err, errOut.String())
159+
t.Fatalf("unexpected non-error: expected %v, but got nothing", test.expectErr)
160+
} else if err != nil && len(test.expectErr) == 0 {
161+
t.Fatalf("unexpected error: expected nothing, but got %v", err.Error())
162+
} else if err != nil && err.Error() != test.expectErr {
163+
t.Fatalf("unexpected error: expected %v, but got %v", test.expectErr, err.Error())
165164
}
166165

167166
if len(test.expectErrOut) == 0 && errOut.Len() > 0 {

0 commit comments

Comments
 (0)