1515package clidocstool
1616
1717import (
18+ "io/fs"
1819 "os"
1920 "path"
2021 "path/filepath"
22+ "strings"
2123 "testing"
2224
23- "github.com/stretchr/testify/assert"
2425 "github.com/stretchr/testify/require"
2526)
2627
2728//nolint:errcheck
2829func TestGenMarkdownTree (t * testing.T ) {
2930 tmpdir := t .TempDir ()
3031
31- err := copyFile (path .Join ("fixtures" , "buildx_stop.pre.md" ), path .Join (tmpdir , "buildx_stop.md" ))
32- require .NoError (t , err )
32+ require .NoError (t , copyFile (path .Join ("fixtures" , "buildx_stop.pre.md" ), path .Join (tmpdir , "buildx_stop.md" )))
3333
3434 c , err := New (Options {
3535 Root : buildxCmd ,
@@ -39,15 +39,39 @@ func TestGenMarkdownTree(t *testing.T) {
3939 require .NoError (t , err )
4040 require .NoError (t , c .GenMarkdownTree (buildxCmd ))
4141
42- for _ , tt := range []string {"buildx.md" , "buildx_build.md" , "buildx_stop.md" } {
43- tt := tt
44- t .Run (tt , func (t * testing.T ) {
45- bres , err := os .ReadFile (filepath .Join (tmpdir , tt ))
42+ seen := make (map [string ]struct {})
43+
44+ filepath .Walk ("fixtures" , func (path string , info fs.FileInfo , err error ) error {
45+ fname := filepath .Base (path )
46+ // ignore dirs, .pre.md files and any file that is not a .md file
47+ if info .IsDir () || ! strings .HasSuffix (fname , ".md" ) || strings .HasSuffix (fname , ".pre.md" ) {
48+ return nil
49+ }
50+ t .Run (fname , func (t * testing.T ) {
51+ seen [fname ] = struct {}{}
52+ require .NoError (t , err )
53+
54+ bres , err := os .ReadFile (filepath .Join (tmpdir , fname ))
4655 require .NoError (t , err )
4756
48- bexc , err := os .ReadFile (path . Join ( "fixtures" , tt ) )
57+ bexc , err := os .ReadFile (path )
4958 require .NoError (t , err )
50- assert .Equal (t , string (bexc ), string (bres ))
59+ require .Equal (t , string (bexc ), string (bres ))
5160 })
52- }
61+ return nil
62+ })
63+
64+ filepath .Walk (tmpdir , func (path string , info fs.FileInfo , err error ) error {
65+ fname := filepath .Base (path )
66+ // ignore dirs, .pre.md files and any file that is not a .md file
67+ if info .IsDir () || ! strings .HasSuffix (fname , ".md" ) || strings .HasSuffix (fname , ".pre.md" ) {
68+ return nil
69+ }
70+ t .Run ("seen_" + fname , func (t * testing.T ) {
71+ if _ , ok := seen [fname ]; ! ok {
72+ t .Errorf ("file %s not found in fixtures" , fname )
73+ }
74+ })
75+ return nil
76+ })
5377}
0 commit comments