MCPcopy Create free account
hub / github.com/compozy/agh / TestNewDocCommand_GeneratesDocs

Function TestNewDocCommand_GeneratesDocs

internal/cli/doc_test.go:83–173  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

81}
82
83func TestNewDocCommand_GeneratesDocs(t *testing.T) {
84 t.Parallel()
85
86 outputDir := filepath.Join(t.TempDir(), "cli-docs")
87
88 root := newRootCommand(commandDeps{})
89 root.SetArgs([]string{"doc", "--output-dir", outputDir})
90
91 if err := root.Execute(); err != nil {
92 t.Fatalf("doc command failed: %v", err)
93 }
94
95 // Verify output directory was created and contains mdx files.
96 mdxFiles := findMDX(t, outputDir)
97 if len(mdxFiles) == 0 {
98 t.Fatal("doc command should generate .mdx files")
99 }
100
101 // Verify agh.mdx exists at the root (from agh.md). Root index.mdx is
102 // hand-authored by the site and preserved by the post-processor.
103 rootMDX := filepath.Join(outputDir, "agh.mdx")
104 data, err := os.ReadFile(rootMDX)
105 if err != nil {
106 t.Fatalf("agh.mdx should exist at root: %v", err)
107 }
108
109 content := string(data)
110 if !strings.Contains(content, "---") {
111 t.Error("agh.mdx should have YAML frontmatter")
112 }
113 if !strings.Contains(content, `title: "agh"`) {
114 t.Error("agh.mdx frontmatter should have title 'agh'")
115 }
116
117 // Per-subdirectory meta.json is auto-generated; walk and ensure at least
118 // one such file exists (root meta.json is hand-maintained and NOT written).
119 var subdirMetas int
120 err = filepath.WalkDir(outputDir, func(p string, d fs.DirEntry, walkErr error) error {
121 if walkErr != nil {
122 return walkErr
123 }
124 if d.IsDir() {
125 return nil
126 }
127 if d.Name() != "meta.json" {
128 return nil
129 }
130 rel, relErr := filepath.Rel(outputDir, p)
131 if relErr != nil {
132 return relErr
133 }
134 if filepath.Dir(rel) == "." {
135 t.Errorf("doc command must not write root meta.json (hand-maintained)")
136 return nil
137 }
138 subdirMetas++
139 return nil
140 })

Callers

nothing calls this directly

Calls 7

newRootCommandFunction · 0.85
findMDXFunction · 0.85
ContainsMethod · 0.80
ExecuteMethod · 0.65
ReadFileMethod · 0.65
NameMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected