MCPcopy Create free account
hub / github.com/celer-pkg/celer / TestInitCmd_Completion

Function TestInitCmd_Completion

cmds/cmd_init_test.go:52–112  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

50}
51
52func TestInitCmd_Completion(t *testing.T) {
53 // Cleanup.
54 dirs.RemoveAllForTest()
55
56 initCmd := initCmd{}
57 celer := configs.NewCeler()
58 cmd := initCmd.Command(celer)
59
60 tests := []struct {
61 name string
62 toComplete string
63 expected []string
64 }{
65 {
66 name: "complete_url_flag",
67 toComplete: "--u",
68 expected: []string{"--url"},
69 },
70 {
71 name: "complete_url_short_flag",
72 toComplete: "-u",
73 expected: []string{"-u"},
74 },
75 {
76 name: "complete_branch_flag",
77 toComplete: "--b",
78 expected: []string{"--branch"},
79 },
80 {
81 name: "complete_branch_short_flag",
82 toComplete: "-b",
83 expected: []string{"-b"},
84 },
85 {
86 name: "no_completion_for_random",
87 toComplete: "--random",
88 expected: []string{},
89 },
90 }
91
92 for _, test := range tests {
93 t.Run(test.name, func(t *testing.T) {
94 suggestions, directive := initCmd.completion(cmd, []string{}, test.toComplete)
95
96 if directive != cobra.ShellCompDirectiveNoFileComp {
97 t.Errorf("Expected directive %v, got %v", cobra.ShellCompDirectiveNoFileComp, directive)
98 }
99
100 if len(suggestions) != len(test.expected) {
101 t.Errorf("Expected %d suggestions, got %d: %v", len(test.expected), len(suggestions), suggestions)
102 return
103 }
104
105 for i, expected := range test.expected {
106 if i < len(suggestions) && suggestions[i] != expected {
107 t.Errorf("Expected suggestion[%d] to be %s, got %s", i, expected, suggestions[i])
108 }
109 }

Callers

nothing calls this directly

Calls 4

CommandMethod · 0.95
completionMethod · 0.95
RemoveAllForTestFunction · 0.92
NewCelerFunction · 0.92

Tested by

no test coverage detected