MCPcopy Index your code
hub / github.com/larksuite/cli / TestCommandCatalogPath

Function TestCommandCatalogPath

cmd/command_catalog_path_test.go:17–52  ·  view source on GitHub ↗

TestCommandCatalogPath pins that the auth-hint path reconstruction inverts the service command tree for any depth — flat dotted resources AND genuinely nested resources — so it round-trips through apicatalog.Resolve instead of assuming a fixed root->service->resource->method shape.

(t *testing.T)

Source from the content-addressed store, hash-verified

15// nested resources — so it round-trips through apicatalog.Resolve instead of
16// assuming a fixed root->service->resource->method shape.
17func TestCommandCatalogPath(t *testing.T) {
18 chain := func(names ...string) *cobra.Command {
19 var parent, leaf *cobra.Command
20 for _, n := range names {
21 c := &cobra.Command{Use: n}
22 if parent != nil {
23 parent.AddCommand(c)
24 }
25 parent = c
26 leaf = c
27 }
28 return leaf
29 }
30
31 tests := []struct {
32 name string
33 leaf *cobra.Command
34 want []string
35 }{
36 {"flat dotted resource", chain("lark-cli", "im", "chat.members", "create"), []string{"im", "chat.members", "create"}},
37 {"nested resources", chain("lark-cli", "im", "spaces", "items", "get"), []string{"im", "spaces", "items", "get"}},
38 {"service level", chain("lark-cli", "im"), []string{"im"}},
39 }
40 for _, tt := range tests {
41 t.Run(tt.name, func(t *testing.T) {
42 if got := commandCatalogPath(tt.leaf); !reflect.DeepEqual(got, tt.want) {
43 t.Errorf("commandCatalogPath = %v, want %v", got, tt.want)
44 }
45 })
46 }
47
48 // The root command (no parent) has no catalog path.
49 if got := commandCatalogPath(&cobra.Command{Use: "lark-cli"}); len(got) != 0 {
50 t.Errorf("root path = %v, want empty", got)
51 }
52}

Callers

nothing calls this directly

Calls 2

commandCatalogPathFunction · 0.85
RunMethod · 0.65

Tested by

no test coverage detected