Skip to content

Commit 09b167b

Browse files
committed
add test for generating docs
1 parent d24513f commit 09b167b

1 file changed

Lines changed: 76 additions & 0 deletions

File tree

pkg/cli/docs_test.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package cli_test
2+
3+
import (
4+
"mokapi/pkg/cli"
5+
"strings"
6+
"testing"
7+
8+
"github.com/stretchr/testify/require"
9+
)
10+
11+
func TestDocs(t *testing.T) {
12+
testcases := []struct {
13+
name string
14+
args []string
15+
test func(t *testing.T)
16+
}{
17+
{
18+
name: "string value",
19+
test: func(t *testing.T) {
20+
c := cli.Command{Run: func(cmd *cli.Command, args []string) error {
21+
return nil
22+
}}
23+
c.Flags().String("foo", "", cli.FlagDoc{})
24+
sb := &strings.Builder{}
25+
err := c.WriteMarkdown(sb)
26+
require.NoError(t, err)
27+
require.Equal(t, `---
28+
title: Mokapi CLI Flags
29+
description: A complete list of all Mokapi flags, with descriptions, defaults, and examples of how to set the option in config file, environment variables, or CLI.
30+
---
31+
32+
#
33+
34+
35+
36+
<div class="flags">
37+
38+
## Flags
39+
40+
| Name | Usage |
41+
|------|-------|
42+
| --[foo](#foo) | |
43+
| --[help](#help) | Show help information and exit |
44+
45+
46+
</div>
47+
48+
## <a name=foo></a>foo
49+
50+
51+
52+
| Flag | Env | Type | Default |
53+
|------|------|:----:|:-------:|
54+
| --foo | FOO | string | - |
55+
56+
57+
## <a name=help></a>help
58+
59+
Show help information and exit
60+
61+
| Flag | Env | Type | Default |
62+
|------|------|:----:|:-------:|
63+
| --help | HELP | bool | false |
64+
65+
66+
`, sb.String())
67+
},
68+
},
69+
}
70+
for _, tc := range testcases {
71+
tc := tc
72+
t.Run(tc.name, func(t *testing.T) {
73+
tc.test(t)
74+
})
75+
}
76+
}

0 commit comments

Comments
 (0)