github.com/swisscom/cloudfoundry-cli@v7.1.0+incompatible/actor/v2action/organization_summary_test.go (about) 1 package v2action_test 2 3 import ( 4 "errors" 5 6 . "code.cloudfoundry.org/cli/actor/v2action" 7 "code.cloudfoundry.org/cli/actor/v2action/v2actionfakes" 8 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv2" 9 . "github.com/onsi/ginkgo" 10 . "github.com/onsi/gomega" 11 ) 12 13 var _ = Describe("Organization Summary Actions", func() { 14 var ( 15 actor *Actor 16 fakeCloudControllerClient *v2actionfakes.FakeCloudControllerClient 17 orgSummary OrganizationSummary 18 warnings Warnings 19 err error 20 expectedErr error 21 ) 22 23 BeforeEach(func() { 24 fakeCloudControllerClient = new(v2actionfakes.FakeCloudControllerClient) 25 actor = NewActor(fakeCloudControllerClient, nil, nil) 26 }) 27 28 JustBeforeEach(func() { 29 orgSummary, warnings, err = actor.GetOrganizationSummaryByName("some-org") 30 }) 31 32 Describe("GetOrganizationSummaryByName", func() { 33 When("no errors are encountered", func() { 34 BeforeEach(func() { 35 fakeCloudControllerClient.GetOrganizationsReturns( 36 []ccv2.Organization{ 37 { 38 GUID: "some-org-guid", 39 Name: "some-org", 40 QuotaDefinitionGUID: "some-quota-definition-guid", 41 }, 42 }, 43 ccv2.Warnings{"warning-1", "warning-2"}, 44 nil) 45 46 fakeCloudControllerClient.GetSharedDomainsReturns( 47 []ccv2.Domain{ 48 { 49 GUID: "shared-domain-guid-2", 50 Name: "shared-domain-2", 51 }, 52 { 53 GUID: "shared-domain-guid-1", 54 Name: "shared-domain-1", 55 }, 56 }, 57 ccv2.Warnings{"warning-3", "warning-4"}, 58 nil) 59 60 fakeCloudControllerClient.GetOrganizationPrivateDomainsReturns( 61 []ccv2.Domain{ 62 { 63 GUID: "private-domain-guid-2", 64 Name: "private-domain-2", 65 }, 66 { 67 GUID: "private-domain-guid-1", 68 Name: "private-domain-1", 69 }, 70 }, 71 ccv2.Warnings{"warning-5", "warning-6"}, 72 nil) 73 74 fakeCloudControllerClient.GetOrganizationQuotaReturns( 75 ccv2.OrganizationQuota{ 76 GUID: "some-org-quota-guid", 77 Name: "some-org-quota", 78 }, 79 ccv2.Warnings{"warning-7", "warning-8"}, 80 nil) 81 82 fakeCloudControllerClient.GetSpacesReturns( 83 []ccv2.Space{ 84 { 85 GUID: "space-2-guid", 86 Name: "space-2", 87 AllowSSH: false, 88 }, 89 { 90 GUID: "space-1-guid", 91 Name: "space-1", 92 AllowSSH: true, 93 }, 94 }, 95 ccv2.Warnings{"warning-9", "warning-10"}, 96 nil) 97 }) 98 99 It("returns the organization summary and all warnings", func() { 100 Expect(fakeCloudControllerClient.GetOrganizationsCallCount()).To(Equal(1)) 101 Expect(fakeCloudControllerClient.GetOrganizationsArgsForCall(0)[0].Values).To(ConsistOf("some-org")) 102 Expect(fakeCloudControllerClient.GetSharedDomainsCallCount()).To(Equal(1)) 103 Expect(fakeCloudControllerClient.GetOrganizationPrivateDomainsCallCount()).To(Equal(1)) 104 Expect(fakeCloudControllerClient.GetOrganizationPrivateDomainsArgsForCall(0)).To(Equal("some-org-guid")) 105 Expect(fakeCloudControllerClient.GetOrganizationQuotaCallCount()).To(Equal(1)) 106 Expect(fakeCloudControllerClient.GetOrganizationQuotaArgsForCall(0)).To(Equal("some-quota-definition-guid")) 107 Expect(fakeCloudControllerClient.GetSpacesCallCount()).To(Equal(1)) 108 Expect(fakeCloudControllerClient.GetSpacesArgsForCall(0)[0].Values).To(ConsistOf("some-org-guid")) 109 110 Expect(orgSummary).To(Equal(OrganizationSummary{ 111 Organization: Organization{ 112 Name: "some-org", 113 GUID: "some-org-guid", 114 QuotaDefinitionGUID: "some-quota-definition-guid", 115 }, 116 QuotaName: "some-org-quota", 117 DomainNames: []string{"private-domain-1", "private-domain-2", "shared-domain-1", "shared-domain-2"}, 118 SpaceNames: []string{"space-1", "space-2"}, 119 })) 120 Expect(warnings).To(ConsistOf([]string{"warning-1", "warning-2", "warning-3", "warning-4", "warning-5", "warning-6", "warning-7", "warning-8", "warning-9", "warning-10"})) 121 Expect(err).NotTo(HaveOccurred()) 122 }) 123 }) 124 125 When("an error is encountered getting the organization", func() { 126 BeforeEach(func() { 127 expectedErr = errors.New("get-orgs-error") 128 fakeCloudControllerClient.GetOrganizationsReturns( 129 []ccv2.Organization{}, 130 ccv2.Warnings{ 131 "warning-1", 132 "warning-2", 133 }, 134 expectedErr, 135 ) 136 }) 137 138 It("returns the error and all warnings", func() { 139 Expect(err).To(MatchError(expectedErr)) 140 Expect(warnings).To(ConsistOf("warning-1", "warning-2")) 141 }) 142 }) 143 144 When("the organization exists", func() { 145 BeforeEach(func() { 146 fakeCloudControllerClient.GetOrganizationsReturns( 147 []ccv2.Organization{ 148 {GUID: "some-org-guid"}, 149 }, 150 ccv2.Warnings{ 151 "warning-1", 152 "warning-2", 153 }, 154 nil, 155 ) 156 }) 157 158 When("an error is encountered getting the organization domains", func() { 159 BeforeEach(func() { 160 expectedErr = errors.New("shared domains error") 161 fakeCloudControllerClient.GetSharedDomainsReturns([]ccv2.Domain{}, ccv2.Warnings{"shared domains warning"}, expectedErr) 162 }) 163 164 It("returns that error and all warnings", func() { 165 Expect(err).To(MatchError(expectedErr)) 166 Expect(warnings).To(ConsistOf("warning-1", "warning-2", "shared domains warning")) 167 }) 168 }) 169 170 When("an error is encountered getting the organization quota", func() { 171 BeforeEach(func() { 172 expectedErr = errors.New("some org quota error") 173 fakeCloudControllerClient.GetOrganizationQuotaReturns(ccv2.OrganizationQuota{}, ccv2.Warnings{"quota warning"}, expectedErr) 174 }) 175 176 It("returns the error and all warnings", func() { 177 Expect(err).To(MatchError(expectedErr)) 178 Expect(warnings).To(ConsistOf("warning-1", "warning-2", "quota warning")) 179 }) 180 }) 181 182 When("an error is encountered getting the organization spaces", func() { 183 BeforeEach(func() { 184 expectedErr = errors.New("cc-get-spaces-error") 185 fakeCloudControllerClient.GetSpacesReturns( 186 []ccv2.Space{}, 187 ccv2.Warnings{"spaces warning"}, 188 expectedErr, 189 ) 190 }) 191 192 It("returns the error and all warnings", func() { 193 Expect(err).To(MatchError(expectedErr)) 194 Expect(warnings).To(ConsistOf("warning-1", "warning-2", "spaces warning")) 195 }) 196 }) 197 }) 198 }) 199 })