(t *testing.T)
| 40 | } |
| 41 | |
| 42 | func TestGenMdxTreeWritesNestedCommandPages(t *testing.T) { |
| 43 | root := &cobra.Command{Use: "algolia", Short: "Algolia CLI"} |
| 44 | events := &cobra.Command{Use: "events", Short: "Manage events"} |
| 45 | sources := &cobra.Command{Use: "sources", Short: "Manage event sources"} |
| 46 | list := &cobra.Command{ |
| 47 | Use: "list", |
| 48 | Short: "List event sources", |
| 49 | Example: "# List sources\n$ algolia events sources list", |
| 50 | RunE: func(*cobra.Command, []string) error { |
| 51 | return nil |
| 52 | }, |
| 53 | } |
| 54 | list.Flags().StringP("format", "F", "json", "Output format") |
| 55 | |
| 56 | sources.AddCommand(list) |
| 57 | events.AddCommand(sources) |
| 58 | root.AddCommand(events) |
| 59 | |
| 60 | dir := t.TempDir() |
| 61 | require.NoError(t, GenMdxTree(root, dir)) |
| 62 | |
| 63 | rootContent := readTestFile(t, filepath.Join(dir, "index.mdx")) |
| 64 | require.Contains(t, rootContent, "public: true") |
| 65 | require.Contains(t, rootContent, "[`algolia events`](/doc/tools/cli/commands/events)") |
| 66 | |
| 67 | eventsContent := readTestFile(t, filepath.Join(dir, "events.mdx")) |
| 68 | require.Contains(t, eventsContent, "public: true") |
| 69 | require.Contains(t, eventsContent, "[`algolia events sources`](/doc/tools/cli/commands/events/sources)") |
| 70 | |
| 71 | listContent := readTestFile(t, filepath.Join(dir, "events", "sources", "list.mdx")) |
| 72 | require.Contains(t, listContent, "algolia events sources list [flags]") |
| 73 | require.Contains(t, listContent, `<ParamField body="-F, --format">`) |
| 74 | } |
| 75 | |
| 76 | func TestGenMdxTreeSupportsCodeOnlyExamples(t *testing.T) { |
| 77 | root := &cobra.Command{ |
nothing calls this directly
no test coverage detected