github.com/orange-cloudfoundry/cli@v7.1.0+incompatible/actor/v7action/organization_summary_test.go (about)

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