github.com/LukasHeimann/cloudfoundrycli/v8@v8.4.4/command/v7/unset_space_quota_command_test.go (about) 1 package v7_test 2 3 import ( 4 "github.com/LukasHeimann/cloudfoundrycli/v8/actor/v7action" 5 "github.com/LukasHeimann/cloudfoundrycli/v8/cf/errors" 6 "github.com/LukasHeimann/cloudfoundrycli/v8/command/commandfakes" 7 "github.com/LukasHeimann/cloudfoundrycli/v8/command/flag" 8 "github.com/LukasHeimann/cloudfoundrycli/v8/command/v7/v7fakes" 9 "github.com/LukasHeimann/cloudfoundrycli/v8/util/configv3" 10 "github.com/LukasHeimann/cloudfoundrycli/v8/util/ui" 11 12 . "github.com/LukasHeimann/cloudfoundrycli/v8/command/v7" 13 . "github.com/onsi/ginkgo" 14 . "github.com/onsi/gomega" 15 . "github.com/onsi/gomega/gbytes" 16 ) 17 18 var _ = Describe("unset-space-quota Command", func() { 19 var ( 20 cmd UnsetSpaceQuotaCommand 21 testUI *ui.UI 22 fakeConfig *commandfakes.FakeConfig 23 fakeSharedActor *commandfakes.FakeSharedActor 24 fakeActor *v7fakes.FakeActor 25 binaryName string 26 executeErr error 27 input *Buffer 28 29 unsetQuotaWarning string 30 currentUser = "some-user" 31 ) 32 33 BeforeEach(func() { 34 input = NewBuffer() 35 testUI = ui.NewTestUI(input, NewBuffer(), NewBuffer()) 36 fakeConfig = new(commandfakes.FakeConfig) 37 fakeSharedActor = new(commandfakes.FakeSharedActor) 38 fakeActor = new(v7fakes.FakeActor) 39 unsetQuotaWarning = RandomString("unset-quota-warning") 40 41 cmd = UnsetSpaceQuotaCommand{ 42 BaseCommand: BaseCommand{ 43 UI: testUI, 44 Config: fakeConfig, 45 SharedActor: fakeSharedActor, 46 Actor: fakeActor, 47 }, 48 } 49 50 binaryName = "faceman" 51 fakeConfig.BinaryNameReturns(binaryName) 52 }) 53 54 JustBeforeEach(func() { 55 executeErr = cmd.Execute(nil) 56 }) 57 58 When("the environment is not set up correctly", func() { 59 BeforeEach(func() { 60 fakeSharedActor.CheckTargetReturns(errors.New("check-target-failure")) 61 }) 62 63 It("does not require a targeted org or space", func() { 64 targetedOrgRequired, targetedSpaceRequired := fakeSharedActor.CheckTargetArgsForCall(0) 65 Expect(targetedOrgRequired).To(BeTrue()) 66 Expect(targetedSpaceRequired).To(BeFalse()) 67 }) 68 69 It("should return the error", func() { 70 Expect(executeErr).To(MatchError("check-target-failure")) 71 }) 72 }) 73 74 When("getting the current user fails", func() { 75 BeforeEach(func() { 76 fakeActor.GetCurrentUserReturns(configv3.User{}, errors.New("current-user-error")) 77 }) 78 79 It("returns the error", func() { 80 Expect(executeErr).To(MatchError("current-user-error")) 81 }) 82 }) 83 84 When("unsetting the quota succeeds", func() { 85 BeforeEach(func() { 86 cmd.RequiredArgs = flag.UnsetSpaceQuotaArgs{} 87 cmd.RequiredArgs.Space = RandomString("space-name") 88 cmd.RequiredArgs.SpaceQuota = RandomString("space-quota-name") 89 90 fakeActor.UnsetSpaceQuotaReturns( 91 v7action.Warnings{unsetQuotaWarning}, 92 nil) 93 94 fakeConfig.TargetedOrganizationReturns(configv3.Organization{ 95 Name: "some-org-name", 96 GUID: "some-org-guid", 97 }) 98 99 fakeActor.GetCurrentUserReturns(configv3.User{Name: currentUser}, nil) 100 }) 101 102 It("unsets the quota to the organization", func() { 103 Expect(fakeActor.UnsetSpaceQuotaCallCount()).To(Equal(1)) 104 spaceQuotaName, spaceName, orgGUID := fakeActor.UnsetSpaceQuotaArgsForCall(0) 105 Expect(spaceQuotaName).To(Equal(cmd.RequiredArgs.SpaceQuota)) 106 Expect(spaceName).To(Equal(cmd.RequiredArgs.Space)) 107 Expect(orgGUID).To(Equal("some-org-guid")) 108 }) 109 110 It("displays warnings and returns without error", func() { 111 Expect(executeErr).NotTo(HaveOccurred()) 112 Expect(testUI.Err).To(Say(unsetQuotaWarning)) 113 }) 114 115 It("displays flavor text and returns without error", func() { 116 Expect(executeErr).NotTo(HaveOccurred()) 117 118 Expect(testUI.Out).To(Say("Unassigning space quota %s from space %s as %s...", cmd.RequiredArgs.SpaceQuota, cmd.RequiredArgs.Space, currentUser)) 119 Expect(testUI.Out).To(Say("OK")) 120 }) 121 }) 122 123 When("the quota is already dissociated", func() { 124 BeforeEach(func() { 125 cmd.RequiredArgs = flag.UnsetSpaceQuotaArgs{} 126 cmd.RequiredArgs.Space = RandomString("space-name") 127 cmd.RequiredArgs.SpaceQuota = RandomString("space-quota-name") 128 129 fakeActor.UnsetSpaceQuotaReturns( 130 v7action.Warnings{unsetQuotaWarning}, 131 nil) 132 133 fakeConfig.TargetedOrganizationReturns(configv3.Organization{ 134 Name: "some-org-name", 135 GUID: "some-org-guid", 136 }) 137 138 fakeActor.GetCurrentUserReturns(configv3.User{Name: currentUser}, nil) 139 }) 140 141 It("unsets the quota to the organization", func() { 142 Expect(fakeActor.UnsetSpaceQuotaCallCount()).To(Equal(1)) 143 spaceQuotaName, spaceName, orgGUID := fakeActor.UnsetSpaceQuotaArgsForCall(0) 144 Expect(spaceQuotaName).To(Equal(cmd.RequiredArgs.SpaceQuota)) 145 Expect(spaceName).To(Equal(cmd.RequiredArgs.Space)) 146 Expect(orgGUID).To(Equal("some-org-guid")) 147 }) 148 149 It("displays warnings and returns without error", func() { 150 Expect(executeErr).NotTo(HaveOccurred()) 151 Expect(testUI.Err).To(Say(unsetQuotaWarning)) 152 }) 153 154 It("displays flavor text and returns without error", func() { 155 Expect(executeErr).NotTo(HaveOccurred()) 156 157 Expect(testUI.Out).To(Say("Unassigning space quota %s from space %s as %s...", cmd.RequiredArgs.SpaceQuota, cmd.RequiredArgs.Space, currentUser)) 158 Expect(testUI.Out).To(Say("OK")) 159 }) 160 }) 161 })