refactor(bonfire): run the root without fang so bonfire's root help stays installed (IN-06, quick-261028-rqd)
This commit is contained in:
@@ -103,3 +103,28 @@ func TestCallNoGlobalsHook(t *testing.T) {
|
||||
t.Error("a nil Catalog has commands")
|
||||
}
|
||||
}
|
||||
|
||||
// TestExecuteKeepsRootHelp (IN-06): after Execute the root's help function
|
||||
// is still bonfire's list renderer, not one Execute installed.
|
||||
func TestExecuteKeepsRootHelp(t *testing.T) {
|
||||
plainEnv(t)
|
||||
commands := []Command{{Name: "acme:ok", Description: "Succeed", Run: func(context.Context, Input, Output) error { return nil }}}
|
||||
var buf bytes.Buffer
|
||||
root, err := NewRootIO("acme", commands, strings.NewReader(""), &buf, &buf, WithVersion(goldenVersion))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if code := Execute(context.Background(), root, nil); code != ExitOK {
|
||||
t.Fatalf("Execute: exit %d\n%s", code, buf.String())
|
||||
}
|
||||
want := buf.String()
|
||||
buf.Reset()
|
||||
if code := Execute(context.Background(), root, []string{"list"}); code != ExitOK {
|
||||
t.Fatalf("Execute list: exit %d\n%s", code, buf.String())
|
||||
}
|
||||
buf.Reset()
|
||||
root.HelpFunc()(root, nil)
|
||||
if got := buf.String(); got != want {
|
||||
t.Errorf("root help after Execute:\n%s\nwant the command list:\n%s", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user