@@ -13,15 +13,67 @@ import (
1313 "testing"
1414)
1515
16- func TestTargetWithoutArgument (t * testing.T ) {
16+ func TestTargetWithoutArgumentAndLoggedIn (t * testing.T ) {
1717 orgRepo := & testhelpers.FakeOrgRepository {}
1818 spaceRepo := & testhelpers.FakeSpaceRepository {}
1919 configRepo := & testhelpers.FakeConfigRepository {}
2020 config := configRepo .Login ()
2121 config .Target = "https://api.run.pivotal.io"
2222 fakeUI := callTarget ([]string {}, configRepo , orgRepo , spaceRepo )
2323
24+ assert .Equal (t , len (fakeUI .Outputs ), 4 )
2425 assert .Contains (t , fakeUI .Outputs [0 ], "https://api.run.pivotal.io" )
26+ assert .Contains (t , fakeUI .Outputs [1 ], "user: " )
27+ assert .Contains (t , fakeUI .Outputs [2 ], "No org targeted" )
28+ assert .Contains (t , fakeUI .Outputs [3 ], "No space targeted" )
29+ }
30+
31+ func TestTargetWithoutArgumentsAndNotLoggedIn (t * testing.T ) {
32+ orgRepo := & testhelpers.FakeOrgRepository {}
33+ spaceRepo := & testhelpers.FakeSpaceRepository {}
34+ configRepo := & testhelpers.FakeConfigRepository {}
35+ err := configRepo .ClearSession ()
36+ assert .NoError (t , err )
37+ config , err := configRepo .Get ()
38+ assert .NoError (t , err )
39+ config .Target = "https://api.run.pivotal.io"
40+
41+ fakeUI := callTarget ([]string {}, configRepo , orgRepo , spaceRepo )
42+ assert .Equal (t , len (fakeUI .Outputs ), 2 )
43+ assert .Contains (t , fakeUI .Outputs [0 ], "https://api.run.pivotal.io" )
44+ assert .Contains (t , fakeUI .Outputs [1 ], "Logged out." )
45+ }
46+
47+ func TestTargetWithOrganizationFlagAndNotLoggedIn (t * testing.T ) {
48+ orgRepo := & testhelpers.FakeOrgRepository {}
49+ spaceRepo := & testhelpers.FakeSpaceRepository {}
50+ configRepo := & testhelpers.FakeConfigRepository {}
51+ err := configRepo .ClearSession ()
52+ assert .NoError (t , err )
53+ config , err := configRepo .Get ()
54+ assert .NoError (t , err )
55+ config .Target = "https://api.run.pivotal.io"
56+
57+ fakeUI := callTarget ([]string {"-o" , "my-organization" }, configRepo , orgRepo , spaceRepo )
58+ assert .Equal (t , len (fakeUI .Outputs ), 2 )
59+ assert .Contains (t , fakeUI .Outputs [0 ], "FAILED" )
60+ assert .Contains (t , fakeUI .Outputs [1 ], "You must be logged in to set an organization. Use 'cf login'." )
61+ }
62+
63+ func TestTargetWithSpaceFlagAndNotLoggedIn (t * testing.T ) {
64+ orgRepo := & testhelpers.FakeOrgRepository {}
65+ spaceRepo := & testhelpers.FakeSpaceRepository {}
66+ configRepo := & testhelpers.FakeConfigRepository {}
67+ err := configRepo .ClearSession ()
68+ assert .NoError (t , err )
69+ config , err := configRepo .Get ()
70+ assert .NoError (t , err )
71+ config .Target = "https://api.run.pivotal.io"
72+
73+ fakeUI := callTarget ([]string {"-s" , "my-space" }, configRepo , orgRepo , spaceRepo )
74+ assert .Equal (t , len (fakeUI .Outputs ), 2 )
75+ assert .Contains (t , fakeUI .Outputs [0 ], "FAILED" )
76+ assert .Contains (t , fakeUI .Outputs [1 ], "You must be logged in to set a space. Use 'cf login'." )
2577}
2678
2779// With target argument
0 commit comments