MCPcopy Create free account
hub / github.com/dropbox/dbxcli / TestJSONHelpPreservesHelpCommandCompletions

Function TestJSONHelpPreservesHelpCommandCompletions

cmd/help_json_test.go:823–857  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

821}
822
823func TestJSONHelpPreservesHelpCommandCompletions(t *testing.T) {
824 root := newJSONHelpTestRoot(t)
825 root.InitDefaultHelpCmd()
826 helpCmd, _, err := root.Find([]string{"help"})
827 if err != nil {
828 t.Fatalf("find help command: %v", err)
829 }
830 if helpCmd.ValidArgsFunction == nil {
831 t.Fatal("help command should provide command-name completions")
832 }
833
834 completions, directive := helpCmd.ValidArgsFunction(helpCmd, nil, "l")
835 if directive != cobra.ShellCompDirectiveNoFileComp {
836 t.Fatalf("directive = %v, want no-file-completion", directive)
837 }
838 want := []cobra.Completion{
839 cobra.CompletionWithDesc("login", "Log in and save Dropbox credentials"),
840 cobra.CompletionWithDesc("logout", "Log out of the current session"),
841 cobra.CompletionWithDesc("ls", "List files and folders"),
842 }
843 if !reflect.DeepEqual(completions, want) {
844 t.Fatalf("completions = %v, want %v", completions, want)
845 }
846
847 completions, directive = helpCmd.ValidArgsFunction(helpCmd, nil, "h")
848 if directive != cobra.ShellCompDirectiveNoFileComp {
849 t.Fatalf("help directive = %v, want no-file-completion", directive)
850 }
851 want = []cobra.Completion{
852 cobra.CompletionWithDesc("help", "Help about any command"),
853 }
854 if !reflect.DeepEqual(completions, want) {
855 t.Fatalf("help completions = %v, want %v", completions, want)
856 }
857}
858
859func TestJSONHelpDoesNotChangeCommandExecution(t *testing.T) {
860 var stdout bytes.Buffer

Callers

nothing calls this directly

Calls 1

newJSONHelpTestRootFunction · 0.85

Tested by

no test coverage detected