forked from urfave/cli-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjson_test.go
More file actions
63 lines (55 loc) · 1.64 KB
/
Copy pathjson_test.go
File metadata and controls
63 lines (55 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package docs
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/urfave/cli/v3"
)
func TestToJSONFull(t *testing.T) {
cmd := buildExtendedTestCommand(t)
res, err := ToJSON(cmd)
require.NoError(t, err)
expectFileContent(t, "testdata/expected-json-full.json", string(res))
}
func TestToJSONAllFlagTypes(t *testing.T) {
cmd := buildFlagTest(t)
res, err := ToJSON(cmd)
require.NoError(t, err)
expectFileContent(t, "testdata/expected-json-all-flag-types.json", string(res))
}
func TestToJSONNoFlags(t *testing.T) {
cmd := buildExtendedTestCommand(t)
cmd.Flags = nil
res, err := ToJSON(cmd)
require.NoError(t, err)
expectFileContent(t, "testdata/expected-json-no-flags.json", string(res))
}
func TestToJSONNoCommands(t *testing.T) {
cmd := buildExtendedTestCommand(t)
cmd.Commands = nil
res, err := ToJSON(cmd)
require.NoError(t, err)
expectFileContent(t, "testdata/expected-json-no-commands.json", string(res))
}
func TestToJSONEmptyCommand(t *testing.T) {
cmd := &cli.Command{Name: "empty"}
res, err := ToJSON(cmd)
require.NoError(t, err)
expectFileContent(t, "testdata/expected-json-empty.json", string(res))
}
func TestToJSONHiddenCommand(t *testing.T) {
cmd := &cli.Command{
Name: "root",
Hidden: false,
Flags: []cli.Flag{
&cli.StringFlag{Name: "visible-flag", Usage: "shown"},
&cli.StringFlag{Name: "hidden-flag", Usage: "not shown", Hidden: true},
},
Commands: []*cli.Command{
{Name: "visible-cmd", Usage: "shown"},
{Name: "hidden-cmd", Usage: "not shown", Hidden: true},
},
}
res, err := ToJSON(cmd)
require.NoError(t, err)
expectFileContent(t, "testdata/expected-json-hidden.json", string(res))
}