github.com/sleungcy/cli@v7.1.0+incompatible/actor/v2action/space_quota_test.go (about) 1 package v2action_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/v2action/v2actionfakes" 9 "code.cloudfoundry.org/cli/api/cloudcontroller/ccerror" 10 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv2" 11 . "github.com/onsi/ginkgo" 12 . "github.com/onsi/gomega" 13 ) 14 15 var _ = Describe("SpaceQuota Actions", func() { 16 var ( 17 actor *Actor 18 fakeCloudControllerClient *v2actionfakes.FakeCloudControllerClient 19 ) 20 21 BeforeEach(func() { 22 fakeCloudControllerClient = new(v2actionfakes.FakeCloudControllerClient) 23 actor = NewActor(fakeCloudControllerClient, nil, nil) 24 }) 25 26 Describe("GetSpaceQuota", func() { 27 When("the space quota exists", func() { 28 BeforeEach(func() { 29 fakeCloudControllerClient.GetSpaceQuotaDefinitionReturns( 30 ccv2.SpaceQuota{ 31 GUID: "some-space-quota-guid", 32 Name: "some-space-quota", 33 }, 34 ccv2.Warnings{"warning-1"}, 35 nil, 36 ) 37 }) 38 39 It("returns the space quota and warnings", func() { 40 spaceQuota, warnings, err := actor.GetSpaceQuota("some-space-quota-guid") 41 Expect(err).ToNot(HaveOccurred()) 42 Expect(spaceQuota).To(Equal(SpaceQuota{ 43 GUID: "some-space-quota-guid", 44 Name: "some-space-quota", 45 })) 46 Expect(warnings).To(ConsistOf("warning-1")) 47 48 Expect(fakeCloudControllerClient.GetSpaceQuotaDefinitionCallCount()).To(Equal(1)) 49 Expect(fakeCloudControllerClient.GetSpaceQuotaDefinitionArgsForCall(0)).To(Equal( 50 "some-space-quota-guid")) 51 }) 52 }) 53 54 When("the space quota does not exist", func() { 55 BeforeEach(func() { 56 fakeCloudControllerClient.GetSpaceQuotaDefinitionReturns(ccv2.SpaceQuota{}, nil, ccerror.ResourceNotFoundError{}) 57 }) 58 59 It("returns an SpaceQuotaNotFoundError", func() { 60 _, _, err := actor.GetSpaceQuota("some-space-quota-guid") 61 Expect(err).To(MatchError(actionerror.SpaceQuotaNotFoundError{GUID: "some-space-quota-guid"})) 62 }) 63 }) 64 65 When("the cloud controller client returns an error", func() { 66 var expectedErr error 67 68 BeforeEach(func() { 69 expectedErr = errors.New("some space quota error") 70 fakeCloudControllerClient.GetSpaceQuotaDefinitionReturns(ccv2.SpaceQuota{}, ccv2.Warnings{"warning-1", "warning-2"}, expectedErr) 71 }) 72 73 It("returns the error and warnings", func() { 74 _, warnings, err := actor.GetSpaceQuota("some-space-quota-guid") 75 Expect(err).To(MatchError(expectedErr)) 76 Expect(warnings).To(ConsistOf("warning-1", "warning-2")) 77 }) 78 }) 79 }) 80 81 Describe("GetSpaceQuotaByName", func() { 82 When("the orgGUID is not found", func() { 83 BeforeEach(func() { 84 fakeCloudControllerClient.GetSpaceQuotasReturns( 85 []ccv2.SpaceQuota{}, 86 ccv2.Warnings{ 87 "warning-1", 88 "warning-2", 89 }, 90 actionerror.OrganizationNotFoundError{GUID: "some-org-guid"}, 91 ) 92 }) 93 94 It("returns the OrganizationNotFoundError", func() { 95 spaceQuota, warnings, err := actor.GetSpaceQuotaByName("some-space-quota", "some-org-guid") 96 Expect(spaceQuota).To(Equal(SpaceQuota{})) 97 Expect(warnings).To(ConsistOf("warning-1", "warning-2")) 98 Expect(err).To(MatchError(actionerror.OrganizationNotFoundError{GUID: "some-org-guid"})) 99 }) 100 101 }) 102 103 When("the space quota is not found", func() { 104 BeforeEach(func() { 105 spaceQuota1 := ccv2.SpaceQuota{ 106 Name: "space-quota-1", 107 } 108 spaceQuota2 := ccv2.SpaceQuota{ 109 Name: "space-quota-2", 110 } 111 112 fakeCloudControllerClient.GetSpaceQuotasReturns( 113 []ccv2.SpaceQuota{ 114 spaceQuota1, 115 spaceQuota2, 116 }, 117 ccv2.Warnings{ 118 "warning-1", 119 "warning-2", 120 }, 121 nil, 122 ) 123 }) 124 125 It("returns the QuotaNotFoundForNameError", func() { 126 spaceQuota, warnings, err := actor.GetSpaceQuotaByName("some-space-quota", "some-org-guid") 127 Expect(spaceQuota).To(Equal(SpaceQuota{})) 128 Expect(warnings).To(ConsistOf("warning-1", "warning-2")) 129 Expect(err).To(MatchError(actionerror.QuotaNotFoundForNameError{Name: "some-space-quota"})) 130 }) 131 132 }) 133 134 When("the space quota is found", func() { 135 BeforeEach(func() { 136 spaceQuota1 := ccv2.SpaceQuota{ 137 Name: "space-quota-1", 138 } 139 spaceQuota2 := ccv2.SpaceQuota{ 140 Name: "space-quota-2", 141 } 142 143 fakeCloudControllerClient.GetSpaceQuotasReturns( 144 []ccv2.SpaceQuota{ 145 spaceQuota1, 146 spaceQuota2, 147 }, 148 ccv2.Warnings{ 149 "warning-1", 150 "warning-2", 151 }, 152 nil, 153 ) 154 }) 155 156 It("returns the space quota", func() { 157 spaceQuota, warnings, err := actor.GetSpaceQuotaByName("space-quota-2", "some-org-guid") 158 Expect(spaceQuota).To(Equal(SpaceQuota{Name: "space-quota-2"})) 159 Expect(warnings).To(ConsistOf("warning-1", "warning-2")) 160 Expect(err).ToNot(HaveOccurred()) 161 }) 162 }) 163 }) 164 165 Describe("SetSpaceQuota", func() { 166 When("the client call succeeds", func() { 167 BeforeEach(func() { 168 fakeCloudControllerClient.SetSpaceQuotaReturns( 169 ccv2.Warnings{ 170 "warning-1", 171 "warning-2", 172 }, 173 nil, 174 ) 175 }) 176 177 It("sets the space quota and returns the warnings", func() { 178 warnings, err := actor.SetSpaceQuota("some-space-guid", "some-quota-guid") 179 Expect(err).ToNot(HaveOccurred()) 180 Expect(warnings).To(ConsistOf("warning-1", "warning-2")) 181 }) 182 }) 183 184 When("the client call fails", func() { 185 186 }) 187 }) 188 })