github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/command/v6/orgs_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("orgs Command", func() { 19 var ( 20 cmd OrgsCommand 21 testUI *ui.UI 22 fakeConfig *commandfakes.FakeConfig 23 fakeSharedActor *commandfakes.FakeSharedActor 24 fakeActor *v6fakes.FakeOrgsActor 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.FakeOrgsActor) 34 35 cmd = OrgsCommand{ 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(BeFalse()) 61 Expect(checkTargetedSpaceArg).To(BeFalse()) 62 }) 63 }) 64 65 When("the user is logged in and an org is targeted", func() { 66 When("getting the current user fails", func() { 67 BeforeEach(func() { 68 fakeConfig.CurrentUserReturns(configv3.User{}, errors.New("get-user-error")) 69 }) 70 71 It("returns the error", func() { 72 Expect(executeErr).To(MatchError("get-user-error")) 73 }) 74 }) 75 76 When("getting the current user succeeds", func() { 77 BeforeEach(func() { 78 fakeConfig.CurrentUserReturns( 79 configv3.User{Name: "some-user"}, 80 nil) 81 }) 82 83 When("there are no orgs", func() { 84 BeforeEach(func() { 85 fakeActor.GetOrganizationsReturns( 86 []v2action.Organization{}, 87 v2action.Warnings{"get-orgs-warning"}, 88 nil) 89 }) 90 91 It("displays that there are no orgs", func() { 92 Expect(executeErr).ToNot(HaveOccurred()) 93 94 Expect(testUI.Out).To(Say(`Getting orgs as some-user\.\.\.`)) 95 Expect(testUI.Out).To(Say("")) 96 Expect(testUI.Out).To(Say(`No orgs found\.`)) 97 98 Expect(testUI.Err).To(Say("get-orgs-warning")) 99 100 Expect(fakeActor.GetOrganizationsCallCount()).To(Equal(1)) 101 }) 102 }) 103 104 When("there are multiple orgs", func() { 105 BeforeEach(func() { 106 fakeActor.GetOrganizationsReturns( 107 []v2action.Organization{ 108 {Name: "org-1"}, 109 {Name: "org-2"}, 110 }, 111 v2action.Warnings{"get-orgs-warning"}, 112 nil) 113 }) 114 115 It("displays all the orgs in the org", func() { 116 Expect(executeErr).ToNot(HaveOccurred()) 117 118 Expect(testUI.Out).To(Say(`Getting orgs as some-user\.\.\.`)) 119 Expect(testUI.Out).To(Say("")) 120 Expect(testUI.Out).To(Say("name")) 121 Expect(testUI.Out).To(Say("org-1")) 122 Expect(testUI.Out).To(Say("org-2")) 123 124 Expect(testUI.Err).To(Say("get-orgs-warning")) 125 126 Expect(fakeActor.GetOrganizationsCallCount()).To(Equal(1)) 127 }) 128 }) 129 130 When("a translatable error is encountered getting orgs", func() { 131 BeforeEach(func() { 132 fakeActor.GetOrganizationsReturns( 133 nil, 134 v2action.Warnings{"get-orgs-warning"}, 135 actionerror.OrganizationNotFoundError{Name: "not-found-org"}) 136 }) 137 138 It("returns a translatable error", func() { 139 Expect(executeErr).To(MatchError(actionerror.OrganizationNotFoundError{Name: "not-found-org"})) 140 141 Expect(testUI.Out).To(Say(`Getting orgs as some-user\.\.\.`)) 142 Expect(testUI.Out).To(Say("")) 143 144 Expect(testUI.Err).To(Say("get-orgs-warning")) 145 146 Expect(fakeActor.GetOrganizationsCallCount()).To(Equal(1)) 147 }) 148 }) 149 }) 150 }) 151 })