mirror of
https://github.com/spf13/cobra
synced 2024-11-24 14:47:12 +00:00
add unit tests
This commit is contained in:
parent
8a2769858c
commit
08be2cb981
1 changed files with 41 additions and 0 deletions
|
@ -1887,6 +1887,47 @@ func TestRemoveSingleGroup(t *testing.T) {
|
|||
checkStringContains(t, output, "\nAdditional Commands:\n sub")
|
||||
}
|
||||
|
||||
func TestRemoveHelpCommandGroup(t *testing.T) {
|
||||
rootCmd := &Command{Use: "root", Short: "test", Run: emptyRun}
|
||||
rootCmd.CompletionOptions.DisableDefaultCmd = true
|
||||
|
||||
rootCmd.AddGroup(&Group{ID: "group", Title: "group"})
|
||||
rootCmd.AddCommand(&Command{Use: "child", Short: "c", GroupID: "group", Run: emptyRun})
|
||||
rootCmd.SetHelpCommandGroupID("group")
|
||||
|
||||
rootCmd.RemoveGroup("group")
|
||||
|
||||
output, err := executeCommand(rootCmd, "--help")
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error: %v", err)
|
||||
}
|
||||
|
||||
checkStringOmits(t, output, "\ngroup\n child\n help")
|
||||
checkStringContains(t, output, "\nAvailable Commands:\n child c\n help")
|
||||
}
|
||||
|
||||
func TestRemoveCompletionCommandGroup(t *testing.T) {
|
||||
rootCmd := &Command{Use: "root", Short: "test", Run: emptyRun}
|
||||
|
||||
rootCmd.AddGroup(
|
||||
&Group{ID: "group", Title: "group"},
|
||||
&Group{ID: "help", Title: "help"},
|
||||
)
|
||||
rootCmd.AddCommand(&Command{Use: "child", Short: "c", GroupID: "group", Run: emptyRun})
|
||||
rootCmd.SetHelpCommandGroupID("help")
|
||||
rootCmd.SetCompletionCommandGroupID("group")
|
||||
|
||||
rootCmd.RemoveGroup("group")
|
||||
|
||||
output, err := executeCommand(rootCmd, "--help")
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error: %v", err)
|
||||
}
|
||||
|
||||
checkStringOmits(t, output, "\ngroup\n child\n completion")
|
||||
checkStringContains(t, output, "\nAdditional Commands:\n child c\n completion")
|
||||
}
|
||||
|
||||
func TestRemoveMultipleGroups(t *testing.T) {
|
||||
var rootCmd = &Command{Use: "root", Short: "test", Run: emptyRun}
|
||||
|
||||
|
|
Loading…
Reference in a new issue