github.com/jenspinney/cli@v6.42.1-0.20190207184520-7450c600020e+incompatible/command/v7/reset_space_isolation_segment_command_test.go (about) 1 package v7_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/actor/v7action" 9 "code.cloudfoundry.org/cli/command/commandfakes" 10 "code.cloudfoundry.org/cli/command/v7" 11 "code.cloudfoundry.org/cli/command/v7/v7fakes" 12 "code.cloudfoundry.org/cli/util/configv3" 13 "code.cloudfoundry.org/cli/util/ui" 14 . "github.com/onsi/ginkgo" 15 . "github.com/onsi/gomega" 16 . "github.com/onsi/gomega/gbytes" 17 ) 18 19 var _ = Describe("reset-space-isolation-segment Command", func() { 20 var ( 21 cmd v7.ResetSpaceIsolationSegmentCommand 22 testUI *ui.UI 23 fakeConfig *commandfakes.FakeConfig 24 fakeSharedActor *commandfakes.FakeSharedActor 25 fakeActor *v7fakes.FakeResetSpaceIsolationSegmentActor 26 fakeActorV2 *v7fakes.FakeResetSpaceIsolationSegmentActorV2 27 binaryName string 28 executeErr error 29 space string 30 org string 31 ) 32 33 BeforeEach(func() { 34 testUI = ui.NewTestUI(nil, NewBuffer(), NewBuffer()) 35 fakeConfig = new(commandfakes.FakeConfig) 36 fakeSharedActor = new(commandfakes.FakeSharedActor) 37 fakeActor = new(v7fakes.FakeResetSpaceIsolationSegmentActor) 38 fakeActorV2 = new(v7fakes.FakeResetSpaceIsolationSegmentActorV2) 39 40 cmd = v7.ResetSpaceIsolationSegmentCommand{ 41 UI: testUI, 42 Config: fakeConfig, 43 SharedActor: fakeSharedActor, 44 Actor: fakeActor, 45 ActorV2: fakeActorV2, 46 } 47 48 binaryName = "faceman" 49 fakeConfig.BinaryNameReturns(binaryName) 50 space = "some-space" 51 org = "some-org" 52 }) 53 54 JustBeforeEach(func() { 55 executeErr = cmd.Execute(nil) 56 }) 57 58 When("checking target fails", func() { 59 BeforeEach(func() { 60 fakeSharedActor.CheckTargetReturns(actionerror.NotLoggedInError{BinaryName: binaryName}) 61 }) 62 63 It("returns an error", func() { 64 Expect(executeErr).To(MatchError(actionerror.NotLoggedInError{BinaryName: binaryName})) 65 66 Expect(fakeSharedActor.CheckTargetCallCount()).To(Equal(1)) 67 checkTargetedOrg, checkTargetedSpace := fakeSharedActor.CheckTargetArgsForCall(0) 68 Expect(checkTargetedOrg).To(BeTrue()) 69 Expect(checkTargetedSpace).To(BeFalse()) 70 }) 71 }) 72 73 When("the user is logged in", func() { 74 BeforeEach(func() { 75 fakeConfig.CurrentUserReturns(configv3.User{Name: "banana"}, nil) 76 fakeConfig.TargetedOrganizationReturns(configv3.Organization{ 77 Name: org, 78 GUID: "some-org-guid", 79 }) 80 81 cmd.RequiredArgs.SpaceName = space 82 }) 83 84 When("the space lookup is unsuccessful", func() { 85 BeforeEach(func() { 86 fakeActorV2.GetSpaceByOrganizationAndNameReturns(v2action.Space{}, v2action.Warnings{"warning-1", "warning-2"}, actionerror.SpaceNotFoundError{Name: space}) 87 }) 88 89 It("returns the warnings and error", func() { 90 Expect(executeErr).To(MatchError(actionerror.SpaceNotFoundError{Name: space})) 91 Expect(testUI.Err).To(Say("warning-1")) 92 Expect(testUI.Err).To(Say("warning-2")) 93 }) 94 }) 95 96 When("the space lookup is successful", func() { 97 BeforeEach(func() { 98 fakeActorV2.GetSpaceByOrganizationAndNameReturns(v2action.Space{ 99 Name: space, 100 GUID: "some-space-guid", 101 }, v2action.Warnings{"warning-1", "warning-2"}, nil) 102 }) 103 104 When("the reset changes the isolation segment to platform default", func() { 105 BeforeEach(func() { 106 fakeActor.ResetSpaceIsolationSegmentReturns("", v7action.Warnings{"warning-3", "warning-4"}, nil) 107 }) 108 109 It("Displays the header and okay", func() { 110 Expect(executeErr).ToNot(HaveOccurred()) 111 112 Expect(testUI.Out).To(Say("Resetting isolation segment assignment of space %s in org %s as banana...", space, org)) 113 114 Expect(testUI.Out).To(Say("OK\n\n")) 115 116 Expect(testUI.Err).To(Say("warning-1")) 117 Expect(testUI.Err).To(Say("warning-2")) 118 Expect(testUI.Err).To(Say("warning-3")) 119 Expect(testUI.Err).To(Say("warning-4")) 120 121 Expect(testUI.Out).To(Say("Applications in this space will be placed in the platform default isolation segment.")) 122 Expect(testUI.Out).To(Say("Running applications need a restart to be moved there.")) 123 124 Expect(fakeActor.ResetSpaceIsolationSegmentCallCount()).To(Equal(1)) 125 orgGUID, spaceGUID := fakeActor.ResetSpaceIsolationSegmentArgsForCall(0) 126 Expect(orgGUID).To(Equal("some-org-guid")) 127 Expect(spaceGUID).To(Equal("some-space-guid")) 128 }) 129 }) 130 131 When("the reset changes the isolation segment to the org's default", func() { 132 BeforeEach(func() { 133 fakeActor.ResetSpaceIsolationSegmentReturns("some-org-iso-seg-name", v7action.Warnings{"warning-3", "warning-4"}, nil) 134 }) 135 136 It("Displays the header and okay", func() { 137 Expect(executeErr).ToNot(HaveOccurred()) 138 139 Expect(testUI.Out).To(Say("Resetting isolation segment assignment of space %s in org %s as banana...", space, org)) 140 141 Expect(testUI.Out).To(Say("OK\n\n")) 142 143 Expect(testUI.Err).To(Say("warning-1")) 144 Expect(testUI.Err).To(Say("warning-2")) 145 Expect(testUI.Err).To(Say("warning-3")) 146 Expect(testUI.Err).To(Say("warning-4")) 147 148 Expect(testUI.Out).To(Say("Applications in this space will be placed in isolation segment some-org-iso-seg-name.")) 149 Expect(testUI.Out).To(Say("Running applications need a restart to be moved there.")) 150 151 Expect(fakeActor.ResetSpaceIsolationSegmentCallCount()).To(Equal(1)) 152 orgGUID, spaceGUID := fakeActor.ResetSpaceIsolationSegmentArgsForCall(0) 153 Expect(orgGUID).To(Equal("some-org-guid")) 154 Expect(spaceGUID).To(Equal("some-space-guid")) 155 }) 156 }) 157 158 When("the reset errors", func() { 159 var expectedErr error 160 BeforeEach(func() { 161 expectedErr = errors.New("some error") 162 fakeActor.ResetSpaceIsolationSegmentReturns("some-org-iso-seg", v7action.Warnings{"warning-3", "warning-4"}, expectedErr) 163 }) 164 165 It("returns the warnings and error", func() { 166 Expect(executeErr).To(MatchError(expectedErr)) 167 168 Expect(testUI.Out).To(Say("Resetting isolation segment assignment of space %s in org %s as banana...", space, org)) 169 Expect(testUI.Err).To(Say("warning-1")) 170 Expect(testUI.Err).To(Say("warning-2")) 171 Expect(testUI.Err).To(Say("warning-3")) 172 Expect(testUI.Err).To(Say("warning-4")) 173 }) 174 }) 175 }) 176 }) 177 })