MCPcopy Create free account
hub / github.com/algolia/cli / TestGetCommandsRecursivelyIncludesNestedCommands

Function TestGetCommandsRecursivelyIncludesNestedCommands

internal/docs/mdx_test.go:12–40  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

10)
11
12func TestGetCommandsRecursivelyIncludesNestedCommands(t *testing.T) {
13 root := &cobra.Command{Use: "algolia", Short: "Algolia CLI"}
14 one := &cobra.Command{Use: "one", Short: "Level one"}
15 two := &cobra.Command{Use: "two", Short: "Level two"}
16 three := &cobra.Command{Use: "three", Short: "Level three"}
17 four := &cobra.Command{
18 Use: "four",
19 Short: "Level four",
20 RunE: func(*cobra.Command, []string) error {
21 return nil
22 },
23 }
24
25 three.AddCommand(four)
26 two.AddCommand(three)
27 one.AddCommand(two)
28 root.AddCommand(one)
29
30 commands := getCommands(root)
31 require.Len(t, commands, 1)
32 require.Len(t, commands[0].SubCommands, 1)
33 require.Len(t, commands[0].SubCommands[0].SubCommands, 1)
34 require.Len(t, commands[0].SubCommands[0].SubCommands[0].SubCommands, 1)
35 require.Equal(
36 t,
37 "algolia one two three four",
38 commands[0].SubCommands[0].SubCommands[0].SubCommands[0].Name,
39 )
40}
41
42func TestGenMdxTreeWritesNestedCommandPages(t *testing.T) {
43 root := &cobra.Command{Use: "algolia", Short: "Algolia CLI"}

Callers

nothing calls this directly

Calls 1

getCommandsFunction · 0.85

Tested by

no test coverage detected