-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathhelp_test.go
More file actions
103 lines (82 loc) · 2.57 KB
/
Copy pathhelp_test.go
File metadata and controls
103 lines (82 loc) · 2.57 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package commands
import (
"bytes"
"strings"
"testing"
"github.com/spf13/cobra"
)
func TestRenderRootHelp(t *testing.T) {
configureCLIUX()
var buf bytes.Buffer
renderHelp(rootCmd, &buf)
out := buf.String()
for _, want := range []string{"CORE COMMANDS", "activity", "token", "GETTING STARTED", "DISCOVER", "FLAGS", "--profile", "LEARN MORE", "Use `fizzy commands` to see the full command catalog.", "implies --json"} {
if !strings.Contains(out, want) {
t.Fatalf("expected root help to contain %q, got:\n%s", want, out)
}
}
}
func TestRenderSubcommandHelpIncludesAliasesAndExamples(t *testing.T) {
configureCLIUX()
var buf bytes.Buffer
renderHelp(authListCmd, &buf)
out := buf.String()
if !strings.Contains(out, "ALIASES") || !strings.Contains(out, "ls") {
t.Fatalf("expected alias section in help, got:\n%s", out)
}
if !strings.Contains(out, "EXAMPLES") {
t.Fatalf("expected examples section in help, got:\n%s", out)
}
}
func TestRenderRootHelpOmitsCommonWorkflows(t *testing.T) {
configureCLIUX()
var buf bytes.Buffer
renderHelp(rootCmd, &buf)
out := buf.String()
if strings.Contains(out, "COMMON WORKFLOWS") {
t.Fatalf("expected root help to omit common workflows, got:\n%s", out)
}
}
func TestRenderRunnableParentCommandHelpPreservesDirectUsage(t *testing.T) {
configureCLIUX()
tests := []struct {
name string
cmd *cobra.Command
want string
}{
{name: "signup", cmd: signupCmd, want: " fizzy signup [flags]"},
{name: "setup", cmd: setupCmd, want: " fizzy setup [flags]"},
{name: "skill", cmd: skillCmd, want: " fizzy skill [flags]"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var buf bytes.Buffer
renderHelp(tt.cmd, &buf)
out := buf.String()
if !strings.Contains(out, tt.want) {
t.Fatalf("expected help to contain %q, got:\n%s", tt.want, out)
}
})
}
}
func TestRenderCommandsHelpMentionsJSONCatalog(t *testing.T) {
configureCLIUX()
var buf bytes.Buffer
renderHelp(commandsCmd, &buf)
out := buf.String()
if !strings.Contains(out, "Use --json for a structured command catalog.") {
t.Fatalf("expected commands help to mention --json catalog, got:\n%s", out)
}
if !strings.Contains(out, "EXAMPLES") || !strings.Contains(out, "$ fizzy commands --json") {
t.Fatalf("expected commands help examples to include --json, got:\n%s", out)
}
}
func TestRenderSubcommandHelpDoesNotRepeatJQFlag(t *testing.T) {
configureCLIUX()
var buf bytes.Buffer
renderHelp(boardListCmd, &buf)
out := buf.String()
if strings.Contains(out, "--jq") {
t.Fatalf("expected subcommand help to omit --jq, got:\n%s", out)
}
}