github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/command/v6/spaces_command_test.go (about) 1 package v6_test 2 3 import ( 4 "errors" 5 6 "code.cloudfoundry.org/cli/actor/actionerror" 7 "code.cloudfoundry.org/cli/actor/v2action" 8 "code.cloudfoundry.org/cli/command/commandfakes" 9 . "code.cloudfoundry.org/cli/command/v6" 10 "code.cloudfoundry.org/cli/command/v6/v6fakes" 11 "code.cloudfoundry.org/cli/util/configv3" 12 "code.cloudfoundry.org/cli/util/ui" 13 . "github.com/onsi/ginkgo" 14 . "github.com/onsi/gomega" 15 . "github.com/onsi/gomega/gbytes" 16 ) 17 18 var _ = Describe("spaces Command", func() { 19 var ( 20 cmd SpacesCommand 21 testUI *ui.UI 22 fakeConfig *commandfakes.FakeConfig 23 fakeSharedActor *commandfakes.FakeSharedActor 24 fakeActor *v6fakes.FakeSpacesActor 25 binaryName string 26 executeErr error 27 ) 28 29 BeforeEach(func() { 30 testUI = ui.NewTestUI(nil, NewBuffer(), NewBuffer()) 31 fakeConfig = new(commandfakes.FakeConfig) 32 fakeSharedActor = new(commandfakes.FakeSharedActor) 33 fakeActor = new(v6fakes.FakeSpacesActor) 34 35 cmd = SpacesCommand{ 36 UI: testUI, 37 Config: fakeConfig, 38 SharedActor: fakeSharedActor, 39 Actor: fakeActor, 40 } 41 42 binaryName = "faceman" 43 fakeConfig.BinaryNameReturns(binaryName) 44 }) 45 46 JustBeforeEach(func() { 47 executeErr = cmd.Execute(nil) 48 }) 49 50 When("an error is encountered checking if the environment is setup correctly", func() { 51 BeforeEach(func() { 52 fakeSharedActor.CheckTargetReturns(actionerror.NotLoggedInError{BinaryName: binaryName}) 53 }) 54 55 It("returns an error", func() { 56 Expect(executeErr).To(MatchError(actionerror.NotLoggedInError{BinaryName: binaryName})) 57 58 Expect(fakeSharedActor.CheckTargetCallCount()).To(Equal(1)) 59 checkTargetedOrgArg, checkTargetedSpaceArg := fakeSharedActor.CheckTargetArgsForCall(0) 60 Expect(checkTargetedOrgArg).To(BeTrue()) 61 Expect(checkTargetedSpaceArg).To(BeFalse()) 62 }) 63 }) 64 65 When("the user is logged in and an org is targeted", func() { 66 BeforeEach(func() { 67 fakeConfig.TargetedOrganizationReturns(configv3.Organization{ 68 GUID: "some-org-guid", 69 Name: "some-org", 70 }) 71 }) 72 73 When("getting the current user fails", func() { 74 BeforeEach(func() { 75 fakeConfig.CurrentUserReturns(configv3.User{}, errors.New("get-user-error")) 76 }) 77 78 It("returns the error", func() { 79 Expect(executeErr).To(MatchError("get-user-error")) 80 }) 81 }) 82 83 When("getting the current user succeeds", func() { 84 BeforeEach(func() { 85 fakeConfig.CurrentUserReturns( 86 configv3.User{Name: "some-user"}, 87 nil) 88 }) 89 90 When("there are no spaces", func() { 91 BeforeEach(func() { 92 fakeActor.GetOrganizationSpacesReturns( 93 []v2action.Space{}, 94 v2action.Warnings{"get-spaces-warning"}, 95 nil) 96 }) 97 98 It("displays that there are no spaces", func() { 99 Expect(executeErr).ToNot(HaveOccurred()) 100 101 Expect(testUI.Out).To(Say(`Getting spaces in org some-org as some-user\.\.\.`)) 102 Expect(testUI.Out).To(Say("")) 103 Expect(testUI.Out).To(Say(`No spaces found\.`)) 104 105 Expect(testUI.Err).To(Say("get-spaces-warning")) 106 107 Expect(fakeActor.GetOrganizationSpacesCallCount()).To(Equal(1)) 108 Expect(fakeActor.GetOrganizationSpacesArgsForCall(0)).To(Equal("some-org-guid")) 109 }) 110 }) 111 112 When("there are multiple spaces", func() { 113 BeforeEach(func() { 114 fakeActor.GetOrganizationSpacesReturns( 115 []v2action.Space{ 116 {Name: "space-1"}, 117 {Name: "space-2"}, 118 }, 119 v2action.Warnings{"get-spaces-warning"}, 120 nil) 121 }) 122 123 It("displays all the spaces in the org", func() { 124 Expect(executeErr).ToNot(HaveOccurred()) 125 126 Expect(testUI.Out).To(Say(`Getting spaces in org some-org as some-user\.\.\.`)) 127 Expect(testUI.Out).To(Say("")) 128 Expect(testUI.Out).To(Say("name")) 129 Expect(testUI.Out).To(Say("space-1")) 130 Expect(testUI.Out).To(Say("space-2")) 131 132 Expect(testUI.Err).To(Say("get-spaces-warning")) 133 134 Expect(fakeActor.GetOrganizationSpacesCallCount()).To(Equal(1)) 135 Expect(fakeActor.GetOrganizationSpacesArgsForCall(0)).To(Equal("some-org-guid")) 136 }) 137 }) 138 139 When("a translatable error is encountered getting spaces", func() { 140 BeforeEach(func() { 141 fakeActor.GetOrganizationSpacesReturns( 142 nil, 143 v2action.Warnings{"get-spaces-warning"}, 144 actionerror.OrganizationNotFoundError{Name: "not-found-org"}) 145 }) 146 147 It("returns a translatable error", func() { 148 Expect(executeErr).To(MatchError(actionerror.OrganizationNotFoundError{Name: "not-found-org"})) 149 150 Expect(testUI.Out).To(Say(`Getting spaces in org some-org as some-user\.\.\.`)) 151 Expect(testUI.Out).To(Say("")) 152 153 Expect(testUI.Err).To(Say("get-spaces-warning")) 154 155 Expect(fakeActor.GetOrganizationSpacesCallCount()).To(Equal(1)) 156 Expect(fakeActor.GetOrganizationSpacesArgsForCall(0)).To(Equal("some-org-guid")) 157 }) 158 }) 159 }) 160 }) 161 })