fix(bonfire): recognise cobra's unknown command error once in Execute (IN-03, quick-261028-rqd)
This commit is contained in:
@@ -342,3 +342,34 @@ func TestSanitize(t *testing.T) {
|
||||
t.Errorf("Sanitize(%q) = %q, want it unchanged", clean, got)
|
||||
}
|
||||
}
|
||||
|
||||
// TestPluginErrorWordedUnknownCommand (IN-03): only cobra's own unknown
|
||||
// command error is a usage error. A command whose Run returns an error
|
||||
// worded the same way exits 1 and is printed verbatim, while a mistyped
|
||||
// command still exits 2 with `Command "x" is not defined.` and cobra's
|
||||
// suggestions as Try lines.
|
||||
func TestPluginErrorWordedUnknownCommand(t *testing.T) {
|
||||
plainEnv(t)
|
||||
commands := []Command{
|
||||
{Name: "migrate", Description: "Migrate", Run: func(context.Context, Input, Output) error {
|
||||
return errors.New(`unknown command "x" for "acme"`)
|
||||
}},
|
||||
}
|
||||
_, errOut, code := runGolden(t, commands, "migrate")
|
||||
if code != ExitFailure {
|
||||
t.Errorf("plugin error: exit %d, want %d\n%s", code, ExitFailure, errOut)
|
||||
}
|
||||
if !strings.Contains(errOut, `unknown command "x" for "acme"`) || strings.Contains(errOut, "is not defined") {
|
||||
t.Errorf("plugin error not printed verbatim:\n%s", errOut)
|
||||
}
|
||||
|
||||
_, errOut, code = runGolden(t, commands, "migrat")
|
||||
if code != ExitUsage {
|
||||
t.Errorf("migrat: exit %d, want %d\n%s", code, ExitUsage, errOut)
|
||||
}
|
||||
for _, want := range []string{`Command "migrat" is not defined.`, "Try:", "bin/acme migrate"} {
|
||||
if !strings.Contains(errOut, want) {
|
||||
t.Errorf("migrat: block lacks %q:\n%s", want, errOut)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user