-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_user_cmd_test.go
More file actions
216 lines (157 loc) · 6.93 KB
/
test_user_cmd_test.go
File metadata and controls
216 lines (157 loc) · 6.93 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
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
package main_test
import (
"errors"
. "github.com/benlaplanche/cf-testuser-plugin"
"github.com/cloudfoundry/cli/plugin/fakes"
io_helpers "github.com/cloudfoundry/cli/testhelpers/io"
"github.com/mitchellh/colorstring"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("TestUserCmd", func() {
Describe(".Run", func() {
var fakeCliConnection *fakes.FakeCliConnection
var callCliCommandPlugin *TestUser
BeforeEach(func() {
fakeCliConnection = &fakes.FakeCliConnection{}
callCliCommandPlugin = &TestUser{}
})
Describe("Testing the CLI arguments", func() {
It("returns an error if incorrect number of args supplied", func() {
output := io_helpers.CaptureOutput(func() {
callCliCommandPlugin.Run(fakeCliConnection, []string{"test-user"})
})
Expect(output[0]).To(Equal("Incorrect usage"))
Expect(output[1]).To(Equal("cf test-user <username> <password> <optional org name> <optional space name>"))
})
})
Describe("Testing the happy path", func() {
It("creates a new user", func() {
output := io_helpers.CaptureOutput(func() {
callCliCommandPlugin.Run(fakeCliConnection, []string{"test-user", "me", "password"})
})
Expect(output[0]).To(Equal(colorstring.Color("[green][1/10] Created user me")))
Expect(output[1]).To(Equal(colorstring.Color("[green][2/10] Created Organisation development")))
Expect(output[2]).To(Equal(colorstring.Color("[green][3/10] Created Space development")))
Expect(output[3]).To(Equal(colorstring.Color("[green][4/10] Assigned OrgManager to me in Org development")))
Expect(output[4]).To(Equal(colorstring.Color("[green][5/10] Assigned BillingManager to me in Org development")))
Expect(output[5]).To(Equal(colorstring.Color("[green][6/10] Assigned OrgAuditor to me in Org development")))
Expect(output[6]).To(Equal(colorstring.Color("[green][7/10] Assigned SpaceManager to me in Space development")))
Expect(output[7]).To(Equal(colorstring.Color("[green][8/10] Assigned SpaceDeveloper to me in Space development")))
Expect(output[8]).To(Equal(colorstring.Color("[green][9/10] Assigned SpaceAuditor to me in Space development")))
Expect(output[9]).To(Equal(colorstring.Color("[green][10/10] Logged out and logged in as me")))
})
})
Describe("Cannot create a user", func() {
BeforeEach(func() {
fakeCliConnection.CliCommandWithoutTerminalOutputStub =
func(args ...string) ([]string, error) {
if args[0] == "create-user" {
return nil, errors.New("create user failed")
}
return nil, nil
}
})
It("returns an error", func() {
output := io_helpers.CaptureOutput(func() {
callCliCommandPlugin.Run(fakeCliConnection, []string{"test-user", "me", "password"})
})
Expect(output[0]).To(Equal(colorstring.Color("[red][1/10] Created user me")))
Expect(len(output)).To(Equal(2))
})
})
Describe("Cannot create an org", func() {
BeforeEach(func() {
fakeCliConnection.CliCommandWithoutTerminalOutputStub =
func(args ...string) ([]string, error) {
if args[0] == "create-org" {
return nil, errors.New("create org failed")
}
return nil, nil
}
})
It("returns an error", func() {
output := io_helpers.CaptureOutput(func() {
callCliCommandPlugin.Run(fakeCliConnection, []string{"test-user", "me", "password"})
})
Expect(output[1]).To(Equal(colorstring.Color("[red][2/10] Created Organisation development")))
// Expect(len(output)).To(Equal(3))
})
})
Describe("Cannot create a space", func() {
BeforeEach(func() {
fakeCliConnection.CliCommandWithoutTerminalOutputStub =
func(args ...string) (output []string, err error) {
if args[0] == "create-space" {
return nil, errors.New("create space failed")
}
return nil, nil
}
})
It("returns an error", func() {
output := io_helpers.CaptureOutput(func() {
callCliCommandPlugin.Run(fakeCliConnection, []string{"test-user", "me", "password"})
})
Expect(output[2]).To(Equal(colorstring.Color("[red][3/10] Created Space development")))
Expect(len(output)).To(Equal(4))
})
})
Describe("Org already exists", func() {
BeforeEach(func() {
fakeCliConnection.CliCommandWithoutTerminalOutputStub =
func(args ...string) (output []string, err error) {
if args[0] == "create-org" {
output = append(output, "Creating org development as admin...")
output = append(output, "OK")
output = append(output, "Org development already exists")
return
}
return
}
})
It("returns an error", func() {
output := io_helpers.CaptureOutput(func() {
callCliCommandPlugin.Run(fakeCliConnection, []string{"test-user", "me", "password"})
})
Expect(output[1]).To(Equal(colorstring.Color("[cyan][2/10] Created Organisation development")))
})
})
Describe("Space already exists", func() {
BeforeEach(func() {
fakeCliConnection.CliCommandWithoutTerminalOutputStub =
func(args ...string) (output []string, err error) {
if args[0] == "create-space" {
output = append(output, "Creating space development as admin...")
output = append(output, "OK")
output = append(output, "Space development already exists")
return
}
return
}
})
It("returns an error", func() {
output := io_helpers.CaptureOutput(func() {
callCliCommandPlugin.Run(fakeCliConnection, []string{"test-user", "me", "password"})
})
Expect(output[2]).To(Equal(colorstring.Color("[cyan][3/10] Created Space development")))
})
})
Describe("Specifying a custom organisation and space", func() {
It("creates a the specified organisation and space", func() {
output := io_helpers.CaptureOutput(func() {
callCliCommandPlugin.Run(fakeCliConnection, []string{"test-user", "my-user", "my-password", "my-org", "my-space"})
})
Expect(output[0]).To(Equal(colorstring.Color("[green][1/10] Created user my-user")))
Expect(output[1]).To(Equal(colorstring.Color("[green][2/10] Created Organisation my-org")))
Expect(output[2]).To(Equal(colorstring.Color("[green][3/10] Created Space my-space")))
Expect(output[3]).To(Equal(colorstring.Color("[green][4/10] Assigned OrgManager to my-user in Org my-org")))
Expect(output[4]).To(Equal(colorstring.Color("[green][5/10] Assigned BillingManager to my-user in Org my-org")))
Expect(output[5]).To(Equal(colorstring.Color("[green][6/10] Assigned OrgAuditor to my-user in Org my-org")))
Expect(output[6]).To(Equal(colorstring.Color("[green][7/10] Assigned SpaceManager to my-user in Space my-space")))
Expect(output[7]).To(Equal(colorstring.Color("[green][8/10] Assigned SpaceDeveloper to my-user in Space my-space")))
Expect(output[8]).To(Equal(colorstring.Color("[green][9/10] Assigned SpaceAuditor to my-user in Space my-space")))
Expect(output[9]).To(Equal(colorstring.Color("[green][10/10] Logged out and logged in as my-user")))
})
})
})
})