forked from forcedotcom/heroku-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelp_test.go
163 lines (136 loc) · 4.39 KB
/
help_test.go
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
package main_test
import (
cli "github.com/heroku/cli"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Help", func() {
exit := 9999
BeforeEach(func() {
cli.ExitFn = func(code int) {
if exit == 9999 {
exit = code
}
}
})
AfterEach(func() {
exit = 9999
})
Context(BinaryName+" help", func() {
BeforeEach(func() {
cli.Start(BinaryName, "help")
})
It("exits with code 0", func() { Expect(exit).To(Equal(0)) })
It("shows the help", func() {
Expect(stdout()).To(HavePrefix("Usage: " + BinaryName + " COMMAND [command-specific-options]"))
})
})
Context(BinaryName+" hlp", func() {
BeforeEach(func() {
cli.Start(BinaryName, "hlp")
})
It("exits with code 2", func() { Expect(exit).To(Equal(2)) })
It("has no stdout", func() { Expect(stdout()).To(Equal("")) })
It("shows invalid command message", func() {
Expect(stderr()).To(Equal(` ! hlp is not a ` + BinaryName + ` command.
! Perhaps you meant help?
! Run ` + BinaryName + ` _ to run ` + BinaryName + ` help.
! Run ` + BinaryName + ` help for a list of available commands.
`))
})
It("reruns sfdx help", func() {
cli.Start(BinaryName, "_")
Expect(stdout()).To(HavePrefix("Usage: " + BinaryName + " COMMAND [command-specific-options]"))
})
})
Context(BinaryName+" help plugins", func() {
BeforeEach(func() {
cli.Start(BinaryName, "help", "plugins")
})
It("exits with code 0", func() { Expect(exit).To(Equal(0)) })
It("shows help for plugins command", func() {
Expect(stdout()).To(HavePrefix("Usage: " + BinaryName + " plugins"))
Expect(stdout()).To(ContainSubstring(BinaryName + " plugins:link"))
})
})
Context(BinaryName+" plugins --help", func() {
BeforeEach(func() {
cli.Start(BinaryName, "plugins", "--help")
})
It("exits with code 0", func() { Expect(exit).To(Equal(0)) })
It("shows help for plugins command", func() {
Expect(stdout()).To(HavePrefix("Usage: " + BinaryName + " plugins"))
Expect(stdout()).To(ContainSubstring(BinaryName + " plugins:link"))
})
})
Context(BinaryName+" help plugins:foo", func() {
BeforeEach(func() {
cli.Start(BinaryName, "help", "plugins:foo")
})
It("exits with code 0", func() { Expect(exit).To(Equal(0)) })
It("shows help for plugins commands", func() {
Expect(stdout()).To(HavePrefix("Usage: " + BinaryName + " plugins:COMMAND"))
Expect(stdout()).To(ContainSubstring(BinaryName + " plugins:link"))
})
})
Context(BinaryName+" help plugins", func() {
BeforeEach(func() {
cli.Start(BinaryName, "help", "plugins")
})
It("exits with code 0", func() { Expect(exit).To(Equal(0)) })
It("shows help for plugins commands", func() {
Expect(stdout()).To(ContainSubstring(BinaryName + " plugins:link"))
})
})
Context("help command", func() {
BeforeEach(func() {
cli.AllCommands().Find("help").Run(&cli.Context{})
})
It("exits with code 0", func() { Expect(exit).To(Equal(0)) })
It("shows help", func() {
Expect(stdout()).To(HavePrefix("Usage: " + BinaryName + " COMMAND"))
})
})
Context("help namespace:topic", func() {
BeforeEach(func() {
cli.Start(BinaryName, "help", "heroku:auth")
})
It("exits with code 0", func() { Expect(exit).To(Equal(0)) })
It("shows help", func() {
// Should not show up because we are on a DefaultNamespace heroku (moved to top level)
Expect(stdout()).NotTo(ContainSubstring("auth:2fa"))
})
})
Context("help topic on namespace", func() {
BeforeEach(func() {
cli.BinaryName = "sfdx"
cli.Start(BinaryName, "help", "heroku:auth")
})
It("exits with code 0", func() { Expect(exit).To(Equal(0)) })
It("shows help", func() {
Expect(stdout()).To(ContainSubstring("heroku:auth:2fa"))
})
})
Context("help namespace:topic:command", func() {
BeforeEach(func() {
cli.BinaryName = "sfdx"
cli.Start(BinaryName, "help", "heroku:auth:2fa")
})
It("exits with code 0", func() { Expect(exit).To(Equal(0)) })
It("shows help", func() {
// SHouldn't show topic help, should show command help
Expect(stdout()).To(ContainSubstring("check 2fa status"))
})
})
Context("help with different namespace", func() {
BeforeEach(func() {
cli.BinaryName = "sfdx"
cli.Start(BinaryName, "help")
})
It("exits with code 0", func() { Expect(exit).To(Equal(0)) })
It("shows help", func() {
// SHouldn't show topic help, should show command help
Expect(stdout()).To(ContainSubstring("list all heroku topics"))
})
})
})