rename err to lookupErr

This commit is contained in:
Filip Křepinský 2023-05-15 16:41:54 +02:00
parent 8b9cbe6202
commit bafae5c076

View File

@ -65,7 +65,7 @@ func TestKubectlSubcommandShadowPlugin(t *testing.T) {
args []string args []string
expectPlugin string expectPlugin string
expectPluginArgs []string expectPluginArgs []string
expectError string expectLookupError string
}{ }{
{ {
name: "test that a plugin executable is found based on command args when builtin subcommand does not exist", name: "test that a plugin executable is found based on command args when builtin subcommand does not exist",
@ -76,7 +76,7 @@ func TestKubectlSubcommandShadowPlugin(t *testing.T) {
{ {
name: "test that a plugin executable is not found based on command args when also builtin subcommand does not exist", name: "test that a plugin executable is not found based on command args when also builtin subcommand does not exist",
args: []string{"kubectl", "create", "foo2", "--bar", "--bar2", "--namespace", "test-namespace"}, args: []string{"kubectl", "create", "foo2", "--bar", "--bar2", "--namespace", "test-namespace"},
expectError: "unable to find a plugin executable \"kubectl-create-foo2\"", expectLookupError: "unable to find a plugin executable \"kubectl-create-foo2\"",
}, },
{ {
name: "test that normal commands are able to be executed, when builtin subcommand exists", name: "test that normal commands are able to be executed, when builtin subcommand exists",
@ -148,12 +148,12 @@ func TestKubectlSubcommandShadowPlugin(t *testing.T) {
} }
} }
if (pluginsHandler.err != nil && pluginsHandler.err.Error() != test.expectError) || if (pluginsHandler.lookupErr != nil && pluginsHandler.lookupErr.Error() != test.expectLookupError) ||
(pluginsHandler.err == nil && len(test.expectError) > 0) { (pluginsHandler.lookupErr == nil && len(test.expectLookupError) > 0) {
t.Fatalf("unexpected error: expected %q to occur, but got %q", test.expectError, pluginsHandler.err) t.Fatalf("unexpected error: expected %q to occur, but got %q", test.expectLookupError, pluginsHandler.lookupErr)
} }
if pluginsHandler.lookedup && !pluginsHandler.executed && len(test.expectError) == 0 { if pluginsHandler.lookedup && !pluginsHandler.executed && len(test.expectLookupError) == 0 {
// we have to fail here, because we have found the plugin, but not executed the plugin, nor the command (this would normally result in an error: unknown command) // we have to fail here, because we have found the plugin, but not executed the plugin, nor the command (this would normally result in an error: unknown command)
t.Fatalf("expected plugin execution, but did not occur") t.Fatalf("expected plugin execution, but did not occur")
} }
@ -180,7 +180,7 @@ func TestKubectlCommandHandlesPlugins(t *testing.T) {
args []string args []string
expectPlugin string expectPlugin string
expectPluginArgs []string expectPluginArgs []string
expectError string expectLookupError string
}{ }{
{ {
name: "test that normal commands are able to be executed, when no plugin overshadows them", name: "test that normal commands are able to be executed, when no plugin overshadows them",
@ -269,12 +269,12 @@ func TestKubectlCommandHandlesPlugins(t *testing.T) {
} }
} }
if (pluginsHandler.err != nil && pluginsHandler.err.Error() != test.expectError) || if (pluginsHandler.lookupErr != nil && pluginsHandler.lookupErr.Error() != test.expectLookupError) ||
(pluginsHandler.err == nil && len(test.expectError) > 0) { (pluginsHandler.lookupErr == nil && len(test.expectLookupError) > 0) {
t.Fatalf("unexpected error: expected %q to occur, but got %q", test.expectError, pluginsHandler.err) t.Fatalf("unexpected error: expected %q to occur, but got %q", test.expectLookupError, pluginsHandler.lookupErr)
} }
if pluginsHandler.lookedup && !pluginsHandler.executed && len(test.expectError) == 0 { if pluginsHandler.lookedup && !pluginsHandler.executed && len(test.expectLookupError) == 0 {
// we have to fail here, because we have found the plugin, but not executed the plugin, nor the command (this would normally result in an error: unknown command) // we have to fail here, because we have found the plugin, but not executed the plugin, nor the command (this would normally result in an error: unknown command)
t.Fatalf("expected plugin execution, but did not occur") t.Fatalf("expected plugin execution, but did not occur")
} }
@ -300,7 +300,7 @@ type testPluginHandler struct {
// lookup results // lookup results
lookedup bool lookedup bool
err error lookupErr error
// execution results // execution results
executed bool executed bool
@ -314,18 +314,18 @@ func (h *testPluginHandler) Lookup(filename string) (string, bool) {
dir, err := os.Stat(h.pluginsDirectory) dir, err := os.Stat(h.pluginsDirectory)
if err != nil { if err != nil {
h.err = err h.lookupErr = err
return "", false return "", false
} }
if !dir.IsDir() { if !dir.IsDir() {
h.err = fmt.Errorf("expected %q to be a directory", h.pluginsDirectory) h.lookupErr = fmt.Errorf("expected %q to be a directory", h.pluginsDirectory)
return "", false return "", false
} }
plugins, err := os.ReadDir(h.pluginsDirectory) plugins, err := os.ReadDir(h.pluginsDirectory)
if err != nil { if err != nil {
h.err = err h.lookupErr = err
return "", false return "", false
} }
@ -339,7 +339,7 @@ func (h *testPluginHandler) Lookup(filename string) (string, bool) {
} }
} }
h.err = fmt.Errorf("unable to find a plugin executable %q", filenameWithSuportedPrefix) h.lookupErr = fmt.Errorf("unable to find a plugin executable %q", filenameWithSuportedPrefix)
return "", false return "", false
} }