github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/command/v6/enable_org_isolation_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/v3action" 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("enable-org-isolation Command", func() { 19 var ( 20 cmd EnableOrgIsolationCommand 21 testUI *ui.UI 22 fakeConfig *commandfakes.FakeConfig 23 fakeSharedActor *commandfakes.FakeSharedActor 24 fakeActor *v6fakes.FakeEnableOrgIsolationActor 25 binaryName string 26 executeErr error 27 isolationSegment string 28 org string 29 ) 30 31 BeforeEach(func() { 32 testUI = ui.NewTestUI(nil, NewBuffer(), NewBuffer()) 33 fakeConfig = new(commandfakes.FakeConfig) 34 fakeSharedActor = new(commandfakes.FakeSharedActor) 35 fakeActor = new(v6fakes.FakeEnableOrgIsolationActor) 36 37 cmd = EnableOrgIsolationCommand{ 38 UI: testUI, 39 Config: fakeConfig, 40 SharedActor: fakeSharedActor, 41 Actor: fakeActor, 42 } 43 44 binaryName = "faceman" 45 fakeConfig.BinaryNameReturns(binaryName) 46 org = "some-org" 47 isolationSegment = "segment1" 48 }) 49 50 JustBeforeEach(func() { 51 executeErr = cmd.Execute(nil) 52 }) 53 54 When("checking target fails", func() { 55 BeforeEach(func() { 56 fakeSharedActor.CheckTargetReturns(actionerror.NotLoggedInError{BinaryName: binaryName}) 57 }) 58 59 It("returns an error", func() { 60 Expect(executeErr).To(MatchError(actionerror.NotLoggedInError{BinaryName: binaryName})) 61 62 Expect(fakeSharedActor.CheckTargetCallCount()).To(Equal(1)) 63 checkTargetedOrg, checkTargetedSpace := fakeSharedActor.CheckTargetArgsForCall(0) 64 Expect(checkTargetedOrg).To(BeFalse()) 65 Expect(checkTargetedSpace).To(BeFalse()) 66 }) 67 }) 68 69 When("the user is logged in", func() { 70 BeforeEach(func() { 71 fakeConfig.CurrentUserReturns(configv3.User{Name: "banana"}, nil) 72 73 cmd.RequiredArgs.OrganizationName = org 74 cmd.RequiredArgs.IsolationSegmentName = isolationSegment 75 }) 76 77 When("the enable is successful", func() { 78 BeforeEach(func() { 79 fakeActor.EntitleIsolationSegmentToOrganizationByNameReturns(v3action.Warnings{"I am a warning", "I am also a warning"}, nil) 80 }) 81 82 It("displays the header and ok", func() { 83 Expect(executeErr).ToNot(HaveOccurred()) 84 85 Expect(testUI.Out).To(Say("Enabling isolation segment segment1 for org some-org as banana...")) 86 Expect(testUI.Out).To(Say("OK")) 87 88 Expect(testUI.Err).To(Say("I am a warning")) 89 Expect(testUI.Err).To(Say("I am also a warning")) 90 91 Expect(fakeActor.EntitleIsolationSegmentToOrganizationByNameCallCount()).To(Equal(1)) 92 93 isolationSegmentName, orgName := fakeActor.EntitleIsolationSegmentToOrganizationByNameArgsForCall(0) 94 Expect(orgName).To(Equal(org)) 95 Expect(isolationSegmentName).To(Equal(isolationSegment)) 96 }) 97 }) 98 99 When("the enable is unsuccessful", func() { 100 Context("due to an unexpected error", func() { 101 var expectedErr error 102 103 BeforeEach(func() { 104 expectedErr = errors.New("I am an error") 105 fakeActor.EntitleIsolationSegmentToOrganizationByNameReturns(v3action.Warnings{"I am a warning", "I am also a warning"}, expectedErr) 106 }) 107 108 It("displays the header and error", func() { 109 Expect(executeErr).To(MatchError(expectedErr)) 110 111 Expect(testUI.Out).To(Say("Enabling isolation segment segment1 for org some-org as banana...")) 112 113 Expect(testUI.Err).To(Say("I am a warning")) 114 Expect(testUI.Err).To(Say("I am also a warning")) 115 }) 116 }) 117 118 When("the isolation segment does not exist", func() { 119 BeforeEach(func() { 120 fakeActor.EntitleIsolationSegmentToOrganizationByNameReturns(v3action.Warnings{"I am a warning", "I am also a warning"}, actionerror.IsolationSegmentNotFoundError{Name: "segment1"}) 121 }) 122 123 It("displays all warnings and the isolation segment not found error", func() { 124 Expect(testUI.Err).To(Say("I am a warning")) 125 Expect(testUI.Err).To(Say("I am also a warning")) 126 Expect(executeErr).To(MatchError(actionerror.IsolationSegmentNotFoundError{Name: "segment1"})) 127 }) 128 }) 129 130 When("the organization does not exist", func() { 131 BeforeEach(func() { 132 fakeActor.EntitleIsolationSegmentToOrganizationByNameReturns( 133 v3action.Warnings{"I am a warning", "I am also a warning"}, 134 actionerror.OrganizationNotFoundError{Name: "some-org"}) 135 }) 136 137 It("displays all warnings and the org not found error", func() { 138 Expect(executeErr).To(MatchError(actionerror.OrganizationNotFoundError{Name: "some-org"})) 139 }) 140 }) 141 142 }) 143 }) 144 })