chore: prevent nil dereferences on cmd handlers (#8319)

* chore: detect nil cmd handlers

Prevent nil panic dereferences on cmd handlers. Add a unit test
to prevent future mistakes
This commit is contained in:
Steven Masley
2023-07-05 17:20:12 +00:00
committed by GitHub
parent d70e2d97de
commit 4a008a8f34
5 changed files with 59 additions and 0 deletions
+3
View File
@@ -27,6 +27,9 @@ func (r *RootCmd) provisionerDaemons() *clibase.Cmd {
cmd := &clibase.Cmd{
Use: "provisionerd",
Short: "Manage provisioner daemons",
Handler: func(inv *clibase.Invocation) error {
return inv.Command.HelpHandler(inv)
},
Children: []*clibase.Cmd{
r.provisionerDaemonStart(),
},
+10
View File
@@ -17,3 +17,13 @@ func newCLI(t *testing.T, args ...string) (*clibase.Invocation, config.Root) {
require.NoError(t, err)
return clitest.NewWithCommand(t, cmd, args...)
}
func TestEnterpriseHandlersOK(t *testing.T) {
t.Parallel()
var root cli.RootCmd
cmd, err := root.Command(root.EnterpriseSubcommands())
require.NoError(t, err)
clitest.HandlersOK(t, cmd)
}