@@ -51,7 +51,6 @@ var _ = Describe("sl user detail", func() {
5151 })
5252
5353 Describe ("API Errors" , func () {
54-
5554 It ("SoftLayer_User_Customer::getObject Exception" , func () {
5655 fakeHandler .AddApiError ("SoftLayer_User_Customer" , "getObject" , 500 , "Internal Server Error" )
5756 err := testhelpers .RunCobraCommand (cliCommand .Command , "5555" )
@@ -78,31 +77,6 @@ var _ = Describe("sl user detail", func() {
7877 })
7978 })
8079
81- Describe ("Tests needing a fake UserManager" , func () {
82- var testUser datatypes.User_Customer
83- BeforeEach (func () {
84- testUser = datatypes.User_Customer {}
85- txError := fakeHandler .DoRequest (
86- fakeSession , "SoftLayer_User_Customer" , "getObject" , nil , nil , & testUser ,
87- )
88- Expect (txError ).NotTo (HaveOccurred ())
89- fakeUserManager .GetUserReturnsOnCall (0 , testUser , nil )
90- cliCommand .UserManager = fakeUserManager
91- })
92- It ("SoftLayer_User_Customer::getObject Second Exception Hardware" , func () {
93- fakeUserManager .GetUserReturnsOnCall (1 , datatypes.User_Customer {}, errors .New ("BAD HARDWARE" ))
94- err := testhelpers .RunCobraCommand (cliCommand .Command , "5555" , "--hardware" )
95- Expect (err ).To (HaveOccurred ())
96- Expect (err .Error ()).To (ContainSubstring ("Failed to show hardware." ))
97- })
98- It ("SoftLayer_User_Customer::getObject Second Exception Virtual" , func () {
99- fakeUserManager .GetUserReturnsOnCall (1 , datatypes.User_Customer {}, errors .New ("BAD VIRTUAL" ))
100- err := testhelpers .RunCobraCommand (cliCommand .Command , "5555" , "--virtual" )
101- Expect (err ).To (HaveOccurred ())
102- Expect (err .Error ()).To (ContainSubstring ("Failed to show virual server." ))
103- })
104- })
105-
10680 Describe ("Happy Path Tests" , func () {
10781 It ("return a user" , func () {
10882 err := testhelpers .RunCobraCommand (cliCommand .Command , "5555" )
@@ -142,6 +116,32 @@ var _ = Describe("sl user detail", func() {
142116 })
143117 })
144118
119+ // Since this CLI makes 2 calls to the same API, we need to use the Fake Manager to handle that.
120+ Describe ("API Errors with a Fake Manager" , func () {
121+ var testUser datatypes.User_Customer
122+ BeforeEach (func () {
123+ testUser = datatypes.User_Customer {}
124+ txError := fakeHandler .DoRequest (
125+ fakeSession , "SoftLayer_User_Customer" , "getObject" , nil , nil , & testUser ,
126+ )
127+ Expect (txError ).NotTo (HaveOccurred ())
128+ fakeUserManager .GetUserReturnsOnCall (0 , testUser , nil )
129+ cliCommand .UserManager = fakeUserManager
130+ })
131+ It ("SoftLayer_User_Customer::getObject Second Exception Hardware" , func () {
132+ fakeUserManager .GetUserReturnsOnCall (1 , datatypes.User_Customer {}, errors .New ("BAD HARDWARE" ))
133+ err := testhelpers .RunCobraCommand (cliCommand .Command , "5555" , "--hardware" )
134+ Expect (err ).To (HaveOccurred ())
135+ Expect (err .Error ()).To (ContainSubstring ("Failed to show hardware." ))
136+ })
137+ It ("SoftLayer_User_Customer::getObject Second Exception Virtual" , func () {
138+ fakeUserManager .GetUserReturnsOnCall (1 , datatypes.User_Customer {}, errors .New ("BAD VIRTUAL" ))
139+ err := testhelpers .RunCobraCommand (cliCommand .Command , "5555" , "--virtual" )
140+ Expect (err ).To (HaveOccurred ())
141+ Expect (err .Error ()).To (ContainSubstring ("Failed to show virual server." ))
142+ })
143+ })
144+
145145 Describe ("Happy Path with Fake Manager" , func () {
146146 var testUser datatypes.User_Customer
147147 BeforeEach (func () {
@@ -182,6 +182,44 @@ var _ = Describe("sl user detail", func() {
182182 Expect (fakeUI .Outputs ()).To (ContainSubstring ("3263-10-1-stemcell-bluemix.softlayer.com" ))
183183 Expect (fakeUI .Outputs ()).To (ContainSubstring ("3263-10-2-stemcell-bluemix.softlayer.com" ))
184184 })
185+ It ("JSON with --hardware" , func () {
186+ userHardware := []datatypes.Hardware {}
187+ txError := fakeHandler .DoRequest (
188+ fakeSession , "SoftLayer_Account" , "getHardware" , nil , nil , & userHardware ,
189+ )
190+ testUser .Hardware = userHardware
191+ fakeUserManager .GetUserReturnsOnCall (1 , testUser , nil )
192+ Expect (txError ).NotTo (HaveOccurred ())
193+ err := testhelpers .RunCobraCommand (cliCommand .Command , "5555" , "--output=json" , "--hardware" )
194+ Expect (err ).NotTo (HaveOccurred ())
195+ Expect (fakeUI .Outputs ()).To (ContainSubstring (`"User": {` ))
196+ Expect (fakeUI .Outputs ()).To (ContainSubstring (`"email": "XXX.ASD@ibm.com",` ))
197+ Expect (fakeUI .Outputs ()).To (ContainSubstring (`"Virtual": null,` ))
198+ Expect (fakeUI .Outputs ()).To (ContainSubstring (`"hostname": "ibmcloud-cli-dev1"` ))
199+ Expect (fakeUI .Outputs ()).To (ContainSubstring (`"Events": null,` ))
200+ Expect (fakeUI .Outputs ()).To (ContainSubstring (`"Permissions": null,` ))
201+ Expect (fakeUI .Outputs ()).To (ContainSubstring (`"Logins": null,` ))
202+ Expect (fakeUI .Outputs ()).To (ContainSubstring (`"DedicatedHosts": null` ))
203+ })
204+ It ("JSON with --virtual" , func () {
205+ userGuests := []datatypes.Virtual_Guest {}
206+ txError := fakeHandler .DoRequest (
207+ fakeSession , "SoftLayer_Account" , "getVirtualGuests" , nil , nil , & userGuests ,
208+ )
209+ testUser .VirtualGuests = userGuests
210+ fakeUserManager .GetUserReturnsOnCall (1 , testUser , nil )
211+ Expect (txError ).NotTo (HaveOccurred ())
212+ err := testhelpers .RunCobraCommand (cliCommand .Command , "5555" , "--output=json" , "--virtual" )
213+ Expect (err ).NotTo (HaveOccurred ())
214+ Expect (fakeUI .Outputs ()).To (ContainSubstring (`"User": {` ))
215+ Expect (fakeUI .Outputs ()).To (ContainSubstring (`"email": "XXX.ASD@ibm.com",` ))
216+ Expect (fakeUI .Outputs ()).To (ContainSubstring (`"hostName": "3169-2-stemcell-for-dirtycow",` ))
217+ Expect (fakeUI .Outputs ()).To (ContainSubstring (`"Hardware": null,` ))
218+ Expect (fakeUI .Outputs ()).To (ContainSubstring (`"Events": null,` ))
219+ Expect (fakeUI .Outputs ()).To (ContainSubstring (`"Permissions": null,` ))
220+ Expect (fakeUI .Outputs ()).To (ContainSubstring (`"Logins": null,` ))
221+ Expect (fakeUI .Outputs ()).To (ContainSubstring (`"DedicatedHosts": null` ))
222+ })
185223 It ("return a user without apikey" , func () {
186224 testUser .ApiAuthenticationKeys = []datatypes.User_Customer_ApiAuthentication {}
187225 fakeUserManager .GetUserReturnsOnCall (0 , testUser , nil )
@@ -192,4 +230,56 @@ var _ = Describe("sl user detail", func() {
192230 Expect (fakeUI .Outputs ()).To (ContainSubstring ("Username test" ))
193231 })
194232 })
233+ Describe ("JSON Output tests" , func () {
234+ It ("Just user details" , func () {
235+ err := testhelpers .RunCobraCommand (cliCommand .Command , "5555" , "--output=json" )
236+ Expect (err ).NotTo (HaveOccurred ())
237+ Expect (fakeUI .Outputs ()).To (ContainSubstring (`"User": {` ))
238+ Expect (fakeUI .Outputs ()).To (ContainSubstring (`"email": "XXX.ASD@ibm.com",` ))
239+ Expect (fakeUI .Outputs ()).To (ContainSubstring (`"Virtual": null,` ))
240+ Expect (fakeUI .Outputs ()).To (ContainSubstring (`"Hardware": null,` ))
241+ Expect (fakeUI .Outputs ()).To (ContainSubstring (`"Events": null,` ))
242+ Expect (fakeUI .Outputs ()).To (ContainSubstring (`"Permissions": null,` ))
243+ Expect (fakeUI .Outputs ()).To (ContainSubstring (`"Logins": null,` ))
244+ Expect (fakeUI .Outputs ()).To (ContainSubstring (`"DedicatedHosts": null` ))
245+ })
246+ It ("JSON with --permissions" , func () {
247+ err := testhelpers .RunCobraCommand (cliCommand .Command , "5555" , "--output=json" , "--permissions" )
248+ Expect (err ).NotTo (HaveOccurred ())
249+ Expect (fakeUI .Outputs ()).To (ContainSubstring (`"User": {` ))
250+ Expect (fakeUI .Outputs ()).To (ContainSubstring (`"email": "XXX.ASD@ibm.com",` ))
251+ Expect (fakeUI .Outputs ()).To (ContainSubstring (`"Virtual": null,` ))
252+ Expect (fakeUI .Outputs ()).To (ContainSubstring (`"Hardware": null,` ))
253+ Expect (fakeUI .Outputs ()).To (ContainSubstring (`"Events": null,` ))
254+ Expect (fakeUI .Outputs ()).To (ContainSubstring (`"keyName": "ACCESS_ALL_DEDICATEDHOSTS",` ))
255+ Expect (fakeUI .Outputs ()).To (ContainSubstring (`"Logins": null,` ))
256+ Expect (fakeUI .Outputs ()).To (ContainSubstring (`"DedicatedHosts": null` ))
257+ })
258+
259+ It ("JSON with --logins" , func () {
260+ err := testhelpers .RunCobraCommand (cliCommand .Command , "5555" , "--output=json" , "--logins" )
261+ Expect (err ).NotTo (HaveOccurred ())
262+ Expect (fakeUI .Outputs ()).To (ContainSubstring (`"User": {` ))
263+ Expect (fakeUI .Outputs ()).To (ContainSubstring (`"email": "XXX.ASD@ibm.com",` ))
264+ Expect (fakeUI .Outputs ()).To (ContainSubstring (`"Virtual": null,` ))
265+ Expect (fakeUI .Outputs ()).To (ContainSubstring (`"Hardware": null,` ))
266+ Expect (fakeUI .Outputs ()).To (ContainSubstring (`"Events": null,` ))
267+ Expect (fakeUI .Outputs ()).To (ContainSubstring (`"Permissions": null,` ))
268+ Expect (fakeUI .Outputs ()).To (ContainSubstring (`"ipAddress": "169.60.96.34",` ))
269+ Expect (fakeUI .Outputs ()).To (ContainSubstring (`"Logins": [` ))
270+ Expect (fakeUI .Outputs ()).To (ContainSubstring (`"DedicatedHosts": null` ))
271+ })
272+ It ("JSON with --events" , func () {
273+ err := testhelpers .RunCobraCommand (cliCommand .Command , "5555" , "--output=json" , "--events" )
274+ Expect (err ).NotTo (HaveOccurred ())
275+ Expect (fakeUI .Outputs ()).To (ContainSubstring (`"User": {` ))
276+ Expect (fakeUI .Outputs ()).To (ContainSubstring (`"email": "XXX.ASD@ibm.com",` ))
277+ Expect (fakeUI .Outputs ()).To (ContainSubstring (`"Virtual": null,` ))
278+ Expect (fakeUI .Outputs ()).To (ContainSubstring (`"Hardware": null,` ))
279+ Expect (fakeUI .Outputs ()).To (ContainSubstring (`"eventName": "IAM Token validation successful",` ))
280+ Expect (fakeUI .Outputs ()).To (ContainSubstring (`"Permissions": null,` ))
281+ Expect (fakeUI .Outputs ()).To (ContainSubstring (`"Logins": null,` ))
282+ Expect (fakeUI .Outputs ()).To (ContainSubstring (`"DedicatedHosts": null` ))
283+ })
284+ })
195285})
0 commit comments