MCPcopy Create free account
hub / github.com/larksuite/cli / TestCmdExampleCheck

Function TestCmdExampleCheck

cmd/cmdexample_units_test.go:145–179  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

143}
144
145func TestCmdExampleCheck(t *testing.T) {
146 c := testCatalog()
147 tests := []struct {
148 name string
149 r ref
150 wantKind string // "" = no finding
151 wantPath string
152 }{
153 {"valid shortcut", ref{words: []string{"contact", "+search-user"}, flags: []string{"--query"}}, "", ""},
154 {"valid leaf positional", ref{words: []string{"api", "GET", "/x"}}, "", ""},
155 {"unknown top command", ref{words: []string{"nope"}}, unknownCommand, "nope"},
156 {"group leftover = unknown subcommand",
157 ref{words: []string{"mail", "user_mailbox.messages", "batch_modify_message"}},
158 unknownCommand, "mail user_mailbox.messages batch_modify_message"},
159 {"unknown flag", ref{words: []string{"contact", "+search-user"}, flags: []string{"--nope"}}, unknownFlag, "contact +search-user"},
160 {"universal flag ok", ref{words: []string{"contact", "+search-user"}, flags: []string{"--help"}}, "", ""},
161 }
162 for _, tt := range tests {
163 t.Run(tt.name, func(t *testing.T) {
164 fs := checkRefs(c, []ref{tt.r})
165 if tt.wantKind == "" {
166 if len(fs) != 0 {
167 t.Fatalf("expected no finding, got %+v", fs)
168 }
169 return
170 }
171 if len(fs) != 1 {
172 t.Fatalf("expected 1 finding, got %d: %+v", len(fs), fs)
173 }
174 if fs[0].kind != tt.wantKind || fs[0].path != tt.wantPath {
175 t.Errorf("got kind=%s path=%q, want kind=%s path=%q", fs[0].kind, fs[0].path, tt.wantKind, tt.wantPath)
176 }
177 })
178 }
179}
180
181func TestCmdExampleCheckSuggestsNearest(t *testing.T) {
182 c := testCatalog()

Callers

nothing calls this directly

Calls 3

checkRefsFunction · 0.85
testCatalogFunction · 0.70
RunMethod · 0.65

Tested by

no test coverage detected