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

Function TestCreateCmd_Completion

cmds/cmd_create_test.go:59–120  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

57}
58
59func TestCreateCmd_Completion(t *testing.T) {
60 // Cleanup.
61 dirs.RemoveAllForTest()
62
63 createCmd := createCmd{}
64 celer := configs.NewCeler()
65 cmd := createCmd.Command(celer)
66
67 tests := []struct {
68 name string
69 toComplete string
70 expected []string
71 }{
72 {
73 name: "complete platform flag",
74 toComplete: "--plat",
75 expected: []string{"--platform"},
76 },
77 {
78 name: "complete project flag",
79 toComplete: "--proj",
80 expected: []string{"--project"},
81 },
82 {
83 name: "complete port flag",
84 toComplete: "--port",
85 expected: []string{"--port"},
86 },
87 {
88 name: "no completion for unknown",
89 toComplete: "--unknown",
90 expected: []string{},
91 },
92 {
93 name: "multiple matches",
94 toComplete: "--p",
95 expected: []string{"--platform", "--project", "--port"},
96 },
97 }
98
99 for _, test := range tests {
100 t.Run(test.name, func(t *testing.T) {
101 suggestions, directive := createCmd.completion(cmd, []string{}, test.toComplete)
102
103 if directive != cobra.ShellCompDirectiveNoFileComp {
104 t.Errorf("Expected directive %v, got %v", cobra.ShellCompDirectiveNoFileComp, directive)
105 }
106
107 if len(suggestions) != len(test.expected) {
108 t.Errorf("Expected %d suggestions, got %d: %v", len(test.expected), len(suggestions), suggestions)
109 return
110 }
111
112 for _, expected := range test.expected {
113 found := slices.Contains(suggestions, expected)
114 if !found {
115 t.Errorf("Expected suggestion '%s' not found in %v", expected, suggestions)
116 }

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