package cli //nolint:testpackage // shares runEntry and the command-word constants import ( "testing" "github.com/stretchr/testify/assert" ) // TestEntryGroupRejectsUnknownSubcommand runs each group command with a // mistyped subcommand, as a crontab line might carry one. It must fail // with exit 1 and name the word, as `vaultik bogus` does at the top // level, instead of printing the group's help and exiting 0 having done // nothing. The group name alone still prints its help. // //nolint:paralleltest // replaces os.Args, os.Stdout and os.Stderr func TestEntryGroupRejectsUnknownSubcommand(t *testing.T) { for _, testCase := range []struct { group string mistyped string }{ {group: cmdSnapshot, mistyped: "craete"}, {group: "config", mistyped: "inti"}, {group: cmdRemote, mistyped: "ifno"}, {group: "database", mistyped: "delte"}, {group: "completion", mistyped: "nosuchshell"}, } { t.Run(testCase.group, func(t *testing.T) { code, stdout, stderr := runEntry(t, testCase.group, testCase.mistyped) assert.Equal(t, 1, code) assert.Empty(t, stdout) assert.Contains(t, stderr, `unknown command "`+testCase.mistyped+`"`) code, stdout, _ = runEntry(t, testCase.group) assert.Equal(t, 0, code) assert.Contains(t, stdout, programName+" "+testCase.group+" [command]") }) } }