github.com/orange-cloudfoundry/cli@v7.1.0+incompatible/command/v7/delete_org_quota_command_test.go (about) 1 package v7_test 2 3 import ( 4 "code.cloudfoundry.org/cli/actor/actionerror" 5 "code.cloudfoundry.org/cli/actor/v7action" 6 "code.cloudfoundry.org/cli/cf/errors" 7 "code.cloudfoundry.org/cli/command/commandfakes" 8 . "code.cloudfoundry.org/cli/command/v7" 9 "code.cloudfoundry.org/cli/command/v7/v7fakes" 10 "code.cloudfoundry.org/cli/util/configv3" 11 "code.cloudfoundry.org/cli/util/ui" 12 . "github.com/onsi/ginkgo" 13 . "github.com/onsi/gomega" 14 . "github.com/onsi/gomega/gbytes" 15 ) 16 17 var _ = Describe("delete-org-quota Command", func() { 18 19 var ( 20 cmd DeleteOrgQuotaCommand 21 testUI *ui.UI 22 fakeConfig *commandfakes.FakeConfig 23 fakeSharedActor *commandfakes.FakeSharedActor 24 fakeActor *v7fakes.FakeActor 25 input *Buffer 26 binaryName string 27 quotaName string 28 executeErr error 29 ) 30 31 BeforeEach(func() { 32 input = NewBuffer() 33 fakeActor = new(v7fakes.FakeActor) 34 fakeConfig = new(commandfakes.FakeConfig) 35 fakeSharedActor = new(commandfakes.FakeSharedActor) 36 testUI = ui.NewTestUI(input, NewBuffer(), NewBuffer()) 37 38 binaryName = "faceman" 39 fakeConfig.BinaryNameReturns(binaryName) 40 fakeConfig.CurrentUserReturns(configv3.User{Name: "some-user"}, nil) 41 42 cmd = DeleteOrgQuotaCommand{ 43 BaseCommand: BaseCommand{ 44 Actor: fakeActor, 45 UI: testUI, 46 Config: fakeConfig, 47 SharedActor: fakeSharedActor, 48 }, 49 } 50 51 quotaName = "some-quota" 52 cmd.RequiredArgs.Quota = quotaName 53 cmd.Force = true 54 }) 55 56 JustBeforeEach(func() { 57 executeErr = cmd.Execute(nil) 58 }) 59 60 When("checking target fails", func() { 61 BeforeEach(func() { 62 fakeSharedActor.CheckTargetReturns(actionerror.NotLoggedInError{BinaryName: binaryName}) 63 }) 64 65 It("returns an error if the check fails", func() { 66 Expect(executeErr).To(MatchError(actionerror.NotLoggedInError{BinaryName: binaryName})) 67 68 Expect(fakeSharedActor.CheckTargetCallCount()).To(Equal(1)) 69 shouldCheckTargetedOrg, shouldCheckTargetedSpace := fakeSharedActor.CheckTargetArgsForCall(0) 70 Expect(shouldCheckTargetedOrg).To(BeFalse()) 71 Expect(shouldCheckTargetedSpace).To(BeFalse()) 72 }) 73 }) 74 75 When("the deletion completes successfully", func() { 76 BeforeEach(func() { 77 fakeActor.DeleteOrganizationQuotaReturns(v7action.Warnings{"some-warning"}, nil) 78 }) 79 80 When("--force is specified", func() { 81 BeforeEach(func() { 82 cmd.Force = true 83 }) 84 85 It("calls the actor method correctly", func() { 86 Expect(fakeActor.DeleteOrganizationQuotaCallCount()).To(Equal(1)) 87 88 givenQuotaName := fakeActor.DeleteOrganizationQuotaArgsForCall(0) 89 Expect(givenQuotaName).To(Equal(quotaName)) 90 }) 91 92 It("prints warnings and appropriate output", func() { 93 Expect(testUI.Err).To(Say("some-warning")) 94 Expect(testUI.Out).To(Say("Deleting org quota some-quota as some-user...")) 95 Expect(testUI.Out).To(Say("OK")) 96 }) 97 }) 98 99 When("--force is not specified", func() { 100 BeforeEach(func() { 101 cmd.Force = false 102 }) 103 104 When("the user inputs yes", func() { 105 BeforeEach(func() { 106 _, err := input.Write([]byte("y\n")) 107 Expect(err).ToNot(HaveOccurred()) 108 }) 109 110 It("prompted the user for confirmation", func() { 111 Expect(testUI.Out).To(Say("Really delete the org quota some-quota?")) 112 Expect(testUI.Out).To(Say("Deleting org quota some-quota as some-user...")) 113 Expect(testUI.Out).To(Say("OK")) 114 }) 115 }) 116 117 When("the user inputs no", func() { 118 BeforeEach(func() { 119 _, err := input.Write([]byte("n\n")) 120 Expect(err).ToNot(HaveOccurred()) 121 }) 122 123 It("cancels the delete", func() { 124 Expect(testUI.Out).To(Say("Really delete the org quota some-quota?")) 125 Expect(testUI.Out).To(Say("'some-quota' has not been deleted.")) 126 Expect(testUI.Out).NotTo(Say("Deleting org quota some-quota as some-user...")) 127 }) 128 }) 129 }) 130 }) 131 132 When("the deletion request returns an error", func() { 133 BeforeEach(func() { 134 fakeActor.DeleteOrganizationQuotaReturns( 135 v7action.Warnings{"a-warning"}, 136 errors.New("uh oh"), 137 ) 138 }) 139 140 It("prints warnings and returns error", func() { 141 Expect(executeErr).To(MatchError("uh oh")) 142 Expect(testUI.Err).To(Say("a-warning")) 143 }) 144 }) 145 146 When("the quota does not exist", func() { 147 BeforeEach(func() { 148 fakeActor.DeleteOrganizationQuotaReturns( 149 v7action.Warnings{"a-warning"}, 150 actionerror.OrganizationQuotaNotFoundForNameError{Name: quotaName}, 151 ) 152 }) 153 154 It("prints warnings and helpful message, but exits with OK", func() { 155 Expect(executeErr).NotTo(HaveOccurred()) 156 Expect(testUI.Err).To(Say("a-warning")) 157 Expect(testUI.Err).To(Say(`Organization quota with name 'some-quota' not found\.`)) 158 Expect(testUI.Out).To(Say(`OK`)) 159 }) 160 }) 161 })