github.com/lukasheimann/cloudfoundrycli@v7.1.0+incompatible/actor/v7action/organization_quota_test.go (about)

     1  package v7action_test
     2  
     3  import (
     4  	"errors"
     5  
     6  	"code.cloudfoundry.org/cli/actor/actionerror"
     7  	. "code.cloudfoundry.org/cli/actor/v7action"
     8  	"code.cloudfoundry.org/cli/actor/v7action/v7actionfakes"
     9  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3"
    10  	"code.cloudfoundry.org/cli/resources"
    11  	"code.cloudfoundry.org/cli/types"
    12  	. "github.com/onsi/ginkgo"
    13  	. "github.com/onsi/gomega"
    14  )
    15  
    16  var _ = Describe("Organization Quota Actions", func() {
    17  	var (
    18  		actor                     *Actor
    19  		fakeCloudControllerClient *v7actionfakes.FakeCloudControllerClient
    20  		trueValue                 bool = true
    21  		falseValue                bool = false
    22  	)
    23  
    24  	BeforeEach(func() {
    25  		actor, fakeCloudControllerClient, _, _, _, _, _ = NewTestActor()
    26  	})
    27  
    28  	Describe("ApplyOrganizationQuotaByName", func() {
    29  		var (
    30  			warnings   Warnings
    31  			executeErr error
    32  			quotaName  = "org-quota-name"
    33  			orgGUID    = "org-guid"
    34  		)
    35  
    36  		JustBeforeEach(func() {
    37  			warnings, executeErr = actor.ApplyOrganizationQuotaByName(quotaName, orgGUID)
    38  		})
    39  
    40  		When("when the org quota could not be found", func() {
    41  			BeforeEach(func() {
    42  				fakeCloudControllerClient.GetOrganizationQuotasReturns(
    43  					[]resources.OrganizationQuota{},
    44  					ccv3.Warnings{"some-quota-warning"},
    45  					nil,
    46  				)
    47  			})
    48  
    49  			It("returns the error and prints warnings", func() {
    50  				Expect(fakeCloudControllerClient.GetOrganizationQuotasCallCount()).To(Equal(1))
    51  
    52  				Expect(warnings).To(ConsistOf("some-quota-warning"))
    53  				Expect(executeErr).To(MatchError(actionerror.OrganizationQuotaNotFoundForNameError{Name: quotaName}))
    54  			})
    55  		})
    56  
    57  		When("when applying the quota returns an error", func() {
    58  			BeforeEach(func() {
    59  				fakeCloudControllerClient.GetOrganizationQuotasReturns(
    60  					[]resources.OrganizationQuota{
    61  						{Quota: resources.Quota{GUID: "some-quota-guid"}},
    62  					},
    63  					ccv3.Warnings{"some-quota-warning"},
    64  					nil,
    65  				)
    66  				fakeCloudControllerClient.ApplyOrganizationQuotaReturns(
    67  					resources.RelationshipList{},
    68  					ccv3.Warnings{"apply-quota-warning"},
    69  					errors.New("apply-quota-error"),
    70  				)
    71  			})
    72  
    73  			It("returns the error and prints warnings", func() {
    74  				Expect(fakeCloudControllerClient.GetOrganizationQuotasCallCount()).To(Equal(1))
    75  				Expect(fakeCloudControllerClient.ApplyOrganizationQuotaCallCount()).To(Equal(1))
    76  
    77  				Expect(warnings).To(ConsistOf("some-quota-warning", "apply-quota-warning"))
    78  				Expect(executeErr).To(MatchError("apply-quota-error"))
    79  			})
    80  		})
    81  
    82  		When("Quota is successfully applied to the org", func() {
    83  			var quotaGUID = "some-quota-guid"
    84  			BeforeEach(func() {
    85  				fakeCloudControllerClient.GetOrganizationQuotasReturns(
    86  					[]resources.OrganizationQuota{
    87  						{Quota: resources.Quota{GUID: quotaGUID}},
    88  					},
    89  					ccv3.Warnings{"some-quota-warning"},
    90  					nil,
    91  				)
    92  				fakeCloudControllerClient.ApplyOrganizationQuotaReturns(
    93  					resources.RelationshipList{
    94  						GUIDs: []string{orgGUID},
    95  					},
    96  					ccv3.Warnings{"apply-quota-warning"},
    97  					nil,
    98  				)
    99  			})
   100  
   101  			It("returns the error and prints warnings", func() {
   102  				Expect(fakeCloudControllerClient.GetOrganizationQuotasCallCount()).To(Equal(1))
   103  				passedQuotaQuery := fakeCloudControllerClient.GetOrganizationQuotasArgsForCall(0)
   104  				Expect(passedQuotaQuery).To(Equal([]ccv3.Query{
   105  					{
   106  						Key:    "names",
   107  						Values: []string{quotaName},
   108  					},
   109  				}))
   110  				Expect(fakeCloudControllerClient.ApplyOrganizationQuotaCallCount()).To(Equal(1))
   111  				passedQuotaGUID, passedOrgGUID := fakeCloudControllerClient.ApplyOrganizationQuotaArgsForCall(0)
   112  				Expect(passedQuotaGUID).To(Equal(quotaGUID))
   113  				Expect(passedOrgGUID).To(Equal(orgGUID))
   114  
   115  				Expect(warnings).To(ConsistOf("some-quota-warning", "apply-quota-warning"))
   116  				Expect(executeErr).To(BeNil())
   117  			})
   118  		})
   119  	})
   120  
   121  	Describe("DeleteOrganizationQuota", func() {
   122  		var (
   123  			quotaName  string
   124  			warnings   Warnings
   125  			executeErr error
   126  		)
   127  
   128  		BeforeEach(func() {
   129  			quotaName = "quota-name"
   130  		})
   131  
   132  		JustBeforeEach(func() {
   133  			warnings, executeErr = actor.DeleteOrganizationQuota(quotaName)
   134  		})
   135  
   136  		When("all API calls succeed", func() {
   137  			BeforeEach(func() {
   138  				fakeCloudControllerClient.GetOrganizationQuotasReturns(
   139  					[]resources.OrganizationQuota{{Quota: resources.Quota{Name: quotaName, GUID: "quota-guid"}}},
   140  					ccv3.Warnings{"get-quotas-warning"},
   141  					nil,
   142  				)
   143  
   144  				fakeCloudControllerClient.DeleteOrganizationQuotaReturns(
   145  					"some-job-url",
   146  					ccv3.Warnings{"delete-quota-warning"},
   147  					nil,
   148  				)
   149  
   150  				fakeCloudControllerClient.PollJobReturns(
   151  					ccv3.Warnings{"poll-job-warning"},
   152  					nil,
   153  				)
   154  			})
   155  
   156  			It("returns warnings but no error", func() {
   157  				Expect(fakeCloudControllerClient.GetOrganizationQuotasCallCount()).To(Equal(1))
   158  				query := fakeCloudControllerClient.GetOrganizationQuotasArgsForCall(0)
   159  				Expect(query).To(Equal([]ccv3.Query{
   160  					{Key: ccv3.NameFilter, Values: []string{quotaName}},
   161  				}))
   162  
   163  				Expect(fakeCloudControllerClient.DeleteOrganizationQuotaCallCount()).To(Equal(1))
   164  				givenQuotaGUID := fakeCloudControllerClient.DeleteOrganizationQuotaArgsForCall(0)
   165  				Expect(givenQuotaGUID).To(Equal("quota-guid"))
   166  
   167  				Expect(fakeCloudControllerClient.PollJobCallCount()).To(Equal(1))
   168  				givenJobURL := fakeCloudControllerClient.PollJobArgsForCall(0)
   169  				Expect(givenJobURL).To(Equal(ccv3.JobURL("some-job-url")))
   170  
   171  				Expect(executeErr).NotTo(HaveOccurred())
   172  				Expect(warnings).To(ConsistOf("get-quotas-warning", "delete-quota-warning", "poll-job-warning"))
   173  			})
   174  		})
   175  
   176  		When("getting the quota by name fails", func() {
   177  			BeforeEach(func() {
   178  				fakeCloudControllerClient.GetOrganizationQuotasReturns(
   179  					[]resources.OrganizationQuota{{Quota: resources.Quota{Name: quotaName, GUID: "quota-guid"}}},
   180  					ccv3.Warnings{"get-quotas-warning"},
   181  					nil,
   182  				)
   183  
   184  				fakeCloudControllerClient.DeleteOrganizationQuotaReturns(
   185  					"some-job-url",
   186  					ccv3.Warnings{"delete-quota-warning"},
   187  					errors.New("delete-quota-error"),
   188  				)
   189  			})
   190  
   191  			It("returns error and warnings", func() {
   192  				Expect(executeErr).To(MatchError("delete-quota-error"))
   193  				Expect(warnings).To(ConsistOf("get-quotas-warning", "delete-quota-warning"))
   194  			})
   195  		})
   196  
   197  		When("issuing the delete-quota request fails", func() {
   198  			BeforeEach(func() {
   199  				fakeCloudControllerClient.GetOrganizationQuotasReturns(
   200  					[]resources.OrganizationQuota{{Quota: resources.Quota{Name: quotaName, GUID: "quota-guid"}}},
   201  					ccv3.Warnings{"get-quotas-warning"},
   202  					nil,
   203  				)
   204  
   205  				fakeCloudControllerClient.DeleteOrganizationQuotaReturns(
   206  					"some-job-url",
   207  					ccv3.Warnings{"delete-quota-warning"},
   208  					nil,
   209  				)
   210  
   211  				fakeCloudControllerClient.PollJobReturns(
   212  					ccv3.Warnings{"poll-job-warning"},
   213  					errors.New("poll-job-error"),
   214  				)
   215  			})
   216  
   217  			It("returns error and warnings", func() {
   218  				Expect(executeErr).To(MatchError("poll-job-error"))
   219  				Expect(warnings).To(ConsistOf("get-quotas-warning", "delete-quota-warning", "poll-job-warning"))
   220  			})
   221  		})
   222  
   223  		When("the delete job fails", func() {
   224  			BeforeEach(func() {
   225  				fakeCloudControllerClient.GetOrganizationQuotasReturns(
   226  					[]resources.OrganizationQuota{{Quota: resources.Quota{Name: quotaName, GUID: "quota-guid"}}},
   227  					ccv3.Warnings{"get-quotas-warning"},
   228  					errors.New("get-quotas-error"),
   229  				)
   230  			})
   231  
   232  			It("returns error and warnings", func() {
   233  				Expect(executeErr).To(MatchError("get-quotas-error"))
   234  				Expect(warnings).To(ConsistOf("get-quotas-warning"))
   235  			})
   236  		})
   237  	})
   238  
   239  	Describe("GetOrganizationQuotas", func() {
   240  		var (
   241  			quotas     []resources.OrganizationQuota
   242  			warnings   Warnings
   243  			executeErr error
   244  		)
   245  
   246  		JustBeforeEach(func() {
   247  			quotas, warnings, executeErr = actor.GetOrganizationQuotas()
   248  		})
   249  
   250  		When("getting organization quotas", func() {
   251  			BeforeEach(func() {
   252  				fakeCloudControllerClient.GetOrganizationQuotasReturns(
   253  					[]resources.OrganizationQuota{
   254  						{
   255  							Quota: resources.Quota{
   256  								GUID: "quota-guid",
   257  								Name: "kiwi",
   258  							},
   259  						},
   260  						{
   261  							Quota: resources.Quota{
   262  								GUID: "quota-2-guid",
   263  								Name: "strawberry",
   264  							},
   265  						},
   266  					},
   267  					ccv3.Warnings{"some-quota-warning"},
   268  					nil,
   269  				)
   270  			})
   271  
   272  			It("queries the API and returns organization quotas", func() {
   273  				Expect(executeErr).ToNot(HaveOccurred())
   274  
   275  				Expect(fakeCloudControllerClient.GetOrganizationQuotasCallCount()).To(Equal(1))
   276  
   277  				Expect(quotas).To(ConsistOf(
   278  					resources.OrganizationQuota{
   279  						Quota: resources.Quota{
   280  							GUID: "quota-guid",
   281  							Name: "kiwi",
   282  						},
   283  					},
   284  					resources.OrganizationQuota{
   285  						Quota: resources.Quota{
   286  							GUID: "quota-2-guid",
   287  							Name: "strawberry",
   288  						},
   289  					},
   290  				))
   291  				Expect(warnings).To(ConsistOf("some-quota-warning"))
   292  			})
   293  		})
   294  	})
   295  
   296  	Describe("GetOrganizationQuotaByName", func() {
   297  		var (
   298  			quotaName  string
   299  			quota      resources.OrganizationQuota
   300  			warnings   Warnings
   301  			executeErr error
   302  		)
   303  
   304  		BeforeEach(func() {
   305  			quotaName = "quota-name"
   306  		})
   307  
   308  		JustBeforeEach(func() {
   309  			quota, warnings, executeErr = actor.GetOrganizationQuotaByName(quotaName)
   310  		})
   311  
   312  		When("when the API layer call returns an error", func() {
   313  			BeforeEach(func() {
   314  				fakeCloudControllerClient.GetOrganizationQuotasReturns(
   315  					[]resources.OrganizationQuota{},
   316  					ccv3.Warnings{"some-quota-warning"},
   317  					errors.New("list-error"),
   318  				)
   319  			})
   320  
   321  			It("returns the error and prints warnings", func() {
   322  				Expect(fakeCloudControllerClient.GetOrganizationQuotasCallCount()).To(Equal(1))
   323  
   324  				Expect(warnings).To(ConsistOf("some-quota-warning"))
   325  				Expect(executeErr).To(MatchError("list-error"))
   326  				Expect(quota).To(Equal(resources.OrganizationQuota{}))
   327  			})
   328  		})
   329  
   330  		When("when the org quota could not be found", func() {
   331  			BeforeEach(func() {
   332  				fakeCloudControllerClient.GetOrganizationQuotasReturns(
   333  					[]resources.OrganizationQuota{},
   334  					ccv3.Warnings{"some-quota-warning"},
   335  					nil,
   336  				)
   337  			})
   338  
   339  			It("returns the error and prints warnings", func() {
   340  				Expect(fakeCloudControllerClient.GetOrganizationQuotasCallCount()).To(Equal(1))
   341  
   342  				Expect(warnings).To(ConsistOf("some-quota-warning"))
   343  				Expect(executeErr).To(MatchError(actionerror.OrganizationQuotaNotFoundForNameError{Name: quotaName}))
   344  				Expect(quota).To(Equal(resources.OrganizationQuota{}))
   345  			})
   346  		})
   347  
   348  		When("getting a single quota by name", func() {
   349  			BeforeEach(func() {
   350  				fakeCloudControllerClient.GetOrganizationQuotasReturns(
   351  					[]resources.OrganizationQuota{
   352  						{
   353  							Quota: resources.Quota{
   354  								GUID: "quota-guid",
   355  								Name: quotaName,
   356  							},
   357  						},
   358  					},
   359  					ccv3.Warnings{"some-quota-warning"},
   360  					nil,
   361  				)
   362  			})
   363  
   364  			It("queries the API and returns the matching organization quota", func() {
   365  				Expect(executeErr).ToNot(HaveOccurred())
   366  
   367  				Expect(fakeCloudControllerClient.GetOrganizationQuotasCallCount()).To(Equal(1))
   368  				query := fakeCloudControllerClient.GetOrganizationQuotasArgsForCall(0)
   369  				Expect(query).To(ConsistOf(
   370  					ccv3.Query{Key: ccv3.NameFilter, Values: []string{quotaName}},
   371  				))
   372  
   373  				Expect(warnings).To(ConsistOf("some-quota-warning"))
   374  				Expect(quota).To(Equal(resources.OrganizationQuota{
   375  					Quota: resources.Quota{
   376  						GUID: "quota-guid",
   377  						Name: quotaName,
   378  					},
   379  				}))
   380  			})
   381  		})
   382  	})
   383  
   384  	Describe("CreateOrganizationQuota", func() {
   385  		var (
   386  			quotaName   string
   387  			quotaLimits QuotaLimits
   388  			warnings    Warnings
   389  			executeErr  error
   390  		)
   391  
   392  		BeforeEach(func() {
   393  			quotaName = "quota-name"
   394  			quotaLimits = QuotaLimits{
   395  				TotalMemoryInMB:       &types.NullInt{Value: 2048, IsSet: true},
   396  				PerProcessMemoryInMB:  &types.NullInt{Value: 1024, IsSet: true},
   397  				TotalInstances:        &types.NullInt{Value: 0, IsSet: false},
   398  				TotalServiceInstances: &types.NullInt{Value: 0, IsSet: true},
   399  				PaidServicesAllowed:   &trueValue,
   400  				TotalRoutes:           &types.NullInt{Value: 6, IsSet: true},
   401  				TotalReservedPorts:    &types.NullInt{Value: 5, IsSet: true},
   402  			}
   403  		})
   404  
   405  		JustBeforeEach(func() {
   406  			warnings, executeErr = actor.CreateOrganizationQuota(quotaName, quotaLimits)
   407  		})
   408  
   409  		When("The create org v7Quota endpoint returns an error", func() {
   410  			BeforeEach(func() {
   411  				fakeCloudControllerClient.CreateOrganizationQuotaReturns(
   412  					resources.OrganizationQuota{},
   413  					ccv3.Warnings{"some-quota-warning"},
   414  					errors.New("create-error"),
   415  				)
   416  			})
   417  
   418  			It("returns the error and warnings", func() {
   419  				Expect(fakeCloudControllerClient.CreateOrganizationQuotaCallCount()).To(Equal(1))
   420  
   421  				Expect(warnings).To(ConsistOf("some-quota-warning"))
   422  				Expect(executeErr).To(MatchError("create-error"))
   423  			})
   424  		})
   425  
   426  		When("The create org quota has an empty org quota request", func() {
   427  			var (
   428  				ccv3Quota resources.OrganizationQuota
   429  			)
   430  			BeforeEach(func() {
   431  				quotaName = "quota-name"
   432  				quotaLimits = QuotaLimits{}
   433  
   434  				ccv3Quota = resources.OrganizationQuota{
   435  					Quota: resources.Quota{
   436  						Name: quotaName,
   437  						Apps: resources.AppLimit{
   438  							TotalMemory:       &types.NullInt{Value: 0, IsSet: true},
   439  							InstanceMemory:    nil,
   440  							TotalAppInstances: nil,
   441  						},
   442  						Services: resources.ServiceLimit{
   443  							TotalServiceInstances: &types.NullInt{Value: 0, IsSet: true},
   444  							PaidServicePlans:      nil,
   445  						},
   446  						Routes: resources.RouteLimit{
   447  							TotalRoutes:        &types.NullInt{Value: 0, IsSet: true},
   448  							TotalReservedPorts: &types.NullInt{Value: 0, IsSet: true},
   449  						},
   450  					},
   451  				}
   452  				fakeCloudControllerClient.CreateOrganizationQuotaReturns(
   453  					ccv3Quota,
   454  					ccv3.Warnings{"some-quota-warning"},
   455  					nil,
   456  				)
   457  			})
   458  
   459  			It("call the create endpoint with the respective values and returns warnings", func() {
   460  				Expect(fakeCloudControllerClient.CreateOrganizationQuotaCallCount()).To(Equal(1))
   461  
   462  				Expect(warnings).To(ConsistOf("some-quota-warning"))
   463  
   464  				passedQuota := fakeCloudControllerClient.CreateOrganizationQuotaArgsForCall(0)
   465  				Expect(passedQuota).To(Equal(ccv3Quota))
   466  			})
   467  		})
   468  
   469  		When("The create org quota has all values set to unlimited", func() {
   470  			var (
   471  				ccv3Quota resources.OrganizationQuota
   472  			)
   473  			BeforeEach(func() {
   474  				quotaName = "quota-name"
   475  				quotaLimits = QuotaLimits{
   476  					TotalMemoryInMB:       &types.NullInt{Value: -1, IsSet: true},
   477  					PerProcessMemoryInMB:  &types.NullInt{Value: -1, IsSet: true},
   478  					TotalInstances:        &types.NullInt{Value: -1, IsSet: true},
   479  					PaidServicesAllowed:   &falseValue,
   480  					TotalServiceInstances: &types.NullInt{Value: -1, IsSet: true},
   481  					TotalRoutes:           &types.NullInt{Value: -1, IsSet: true},
   482  					TotalReservedPorts:    &types.NullInt{Value: -1, IsSet: true},
   483  				}
   484  				ccv3Quota = resources.OrganizationQuota{
   485  					Quota: resources.Quota{
   486  						Name: quotaName,
   487  						Apps: resources.AppLimit{
   488  							TotalMemory:       &types.NullInt{Value: 0, IsSet: false},
   489  							InstanceMemory:    &types.NullInt{Value: 0, IsSet: false},
   490  							TotalAppInstances: &types.NullInt{Value: 0, IsSet: false},
   491  						},
   492  						Services: resources.ServiceLimit{
   493  							TotalServiceInstances: &types.NullInt{Value: 0, IsSet: false},
   494  							PaidServicePlans:      &falseValue,
   495  						},
   496  						Routes: resources.RouteLimit{
   497  							TotalRoutes:        &types.NullInt{Value: 0, IsSet: false},
   498  							TotalReservedPorts: &types.NullInt{Value: 0, IsSet: false},
   499  						},
   500  					},
   501  				}
   502  				fakeCloudControllerClient.CreateOrganizationQuotaReturns(
   503  					ccv3Quota,
   504  					ccv3.Warnings{"some-quota-warning"},
   505  					nil,
   506  				)
   507  			})
   508  
   509  			It("call the create endpoint with the respective values and returns warnings", func() {
   510  				Expect(fakeCloudControllerClient.CreateOrganizationQuotaCallCount()).To(Equal(1))
   511  
   512  				Expect(warnings).To(ConsistOf("some-quota-warning"))
   513  
   514  				passedQuota := fakeCloudControllerClient.CreateOrganizationQuotaArgsForCall(0)
   515  				Expect(passedQuota).To(Equal(ccv3Quota))
   516  			})
   517  		})
   518  
   519  		When("The create org quota endpoint succeeds", func() {
   520  			var (
   521  				ccv3Quota resources.OrganizationQuota
   522  			)
   523  			BeforeEach(func() {
   524  				ccv3Quota = resources.OrganizationQuota{
   525  					Quota: resources.Quota{
   526  						Name: quotaName,
   527  						Apps: resources.AppLimit{
   528  							TotalMemory:       &types.NullInt{Value: 2048, IsSet: true},
   529  							InstanceMemory:    &types.NullInt{Value: 1024, IsSet: true},
   530  							TotalAppInstances: &types.NullInt{Value: 0, IsSet: false},
   531  						},
   532  						Services: resources.ServiceLimit{
   533  							TotalServiceInstances: &types.NullInt{Value: 0, IsSet: true},
   534  							PaidServicePlans:      &trueValue,
   535  						},
   536  						Routes: resources.RouteLimit{
   537  							TotalRoutes:        &types.NullInt{Value: 6, IsSet: true},
   538  							TotalReservedPorts: &types.NullInt{Value: 5, IsSet: true},
   539  						},
   540  					},
   541  				}
   542  				fakeCloudControllerClient.CreateOrganizationQuotaReturns(
   543  					ccv3Quota,
   544  					ccv3.Warnings{"some-quota-warning"},
   545  					nil,
   546  				)
   547  			})
   548  
   549  			It("call the create endpoint with the respective values and returns warnings", func() {
   550  				Expect(fakeCloudControllerClient.CreateOrganizationQuotaCallCount()).To(Equal(1))
   551  
   552  				Expect(warnings).To(ConsistOf("some-quota-warning"))
   553  
   554  				passedQuota := fakeCloudControllerClient.CreateOrganizationQuotaArgsForCall(0)
   555  				Expect(passedQuota).To(Equal(ccv3Quota))
   556  			})
   557  		})
   558  	})
   559  
   560  	Describe("UpdateOrganizationQuota", func() {
   561  		var (
   562  			oldQuotaName string
   563  			newQuotaName string
   564  			quotaLimits  QuotaLimits
   565  			warnings     Warnings
   566  			executeErr   error
   567  		)
   568  
   569  		BeforeEach(func() {
   570  			oldQuotaName = "old-quota-name"
   571  			newQuotaName = "new-quota-name"
   572  			quotaLimits = QuotaLimits{
   573  				TotalMemoryInMB:       &types.NullInt{Value: 2048, IsSet: true},
   574  				PerProcessMemoryInMB:  &types.NullInt{Value: 1024, IsSet: true},
   575  				TotalInstances:        &types.NullInt{Value: 0, IsSet: false},
   576  				TotalServiceInstances: &types.NullInt{Value: 0, IsSet: true},
   577  				PaidServicesAllowed:   &trueValue,
   578  				TotalRoutes:           &types.NullInt{Value: 6, IsSet: true},
   579  				TotalReservedPorts:    &types.NullInt{Value: 5, IsSet: true},
   580  			}
   581  
   582  			fakeCloudControllerClient.GetOrganizationQuotasReturns(
   583  				[]resources.OrganizationQuota{{Quota: resources.Quota{Name: oldQuotaName}}},
   584  				ccv3.Warnings{"get-quotas-warning"},
   585  				nil,
   586  			)
   587  		})
   588  
   589  		JustBeforeEach(func() {
   590  			warnings, executeErr = actor.UpdateOrganizationQuota(oldQuotaName, newQuotaName, quotaLimits)
   591  		})
   592  
   593  		When("the update-quota endpoint returns an error", func() {
   594  			BeforeEach(func() {
   595  				fakeCloudControllerClient.UpdateOrganizationQuotaReturns(
   596  					resources.OrganizationQuota{},
   597  					ccv3.Warnings{"update-quota-warning"},
   598  					errors.New("update-error"),
   599  				)
   600  			})
   601  
   602  			It("returns the error and warnings", func() {
   603  				Expect(fakeCloudControllerClient.UpdateOrganizationQuotaCallCount()).To(Equal(1))
   604  
   605  				Expect(warnings).To(ConsistOf("get-quotas-warning", "update-quota-warning"))
   606  				Expect(executeErr).To(MatchError("update-error"))
   607  			})
   608  		})
   609  
   610  		When("no quota limits are being updated", func() {
   611  			var (
   612  				ccv3Quota resources.OrganizationQuota
   613  			)
   614  
   615  			BeforeEach(func() {
   616  				quotaLimits = QuotaLimits{}
   617  
   618  				ccv3Quota = resources.OrganizationQuota{
   619  					Quota: resources.Quota{
   620  						Name: oldQuotaName,
   621  						Apps: resources.AppLimit{
   622  							TotalMemory:       nil,
   623  							InstanceMemory:    nil,
   624  							TotalAppInstances: nil,
   625  						},
   626  						Services: resources.ServiceLimit{
   627  							TotalServiceInstances: nil,
   628  							PaidServicePlans:      nil,
   629  						},
   630  						Routes: resources.RouteLimit{
   631  							TotalRoutes:        nil,
   632  							TotalReservedPorts: nil,
   633  						},
   634  					},
   635  				}
   636  
   637  				fakeCloudControllerClient.UpdateOrganizationQuotaReturns(
   638  					ccv3Quota,
   639  					ccv3.Warnings{"update-quota-warning"},
   640  					nil,
   641  				)
   642  			})
   643  
   644  			It("calls the update endpoint with the respective values and returns warnings", func() {
   645  				Expect(fakeCloudControllerClient.UpdateOrganizationQuotaCallCount()).To(Equal(1))
   646  
   647  				Expect(warnings).To(ConsistOf("get-quotas-warning", "update-quota-warning"))
   648  
   649  				passedQuota := fakeCloudControllerClient.UpdateOrganizationQuotaArgsForCall(0)
   650  
   651  				updatedQuota := ccv3Quota
   652  				updatedQuota.Name = newQuotaName
   653  
   654  				Expect(passedQuota).To(Equal(updatedQuota))
   655  			})
   656  		})
   657  
   658  		When("the update org quota has all values set to unlimited", func() {
   659  			var (
   660  				ccv3Quota resources.OrganizationQuota
   661  			)
   662  
   663  			BeforeEach(func() {
   664  				quotaLimits = QuotaLimits{
   665  					TotalMemoryInMB:       &types.NullInt{Value: -1, IsSet: true},
   666  					PerProcessMemoryInMB:  &types.NullInt{Value: -1, IsSet: true},
   667  					TotalInstances:        &types.NullInt{Value: -1, IsSet: true},
   668  					PaidServicesAllowed:   &falseValue,
   669  					TotalServiceInstances: &types.NullInt{Value: -1, IsSet: true},
   670  					TotalRoutes:           &types.NullInt{Value: -1, IsSet: true},
   671  					TotalReservedPorts:    &types.NullInt{Value: -1, IsSet: true},
   672  				}
   673  				ccv3Quota = resources.OrganizationQuota{
   674  					Quota: resources.Quota{
   675  						Name: oldQuotaName,
   676  						Apps: resources.AppLimit{
   677  							TotalMemory:       &types.NullInt{Value: 0, IsSet: false},
   678  							InstanceMemory:    &types.NullInt{Value: 0, IsSet: false},
   679  							TotalAppInstances: &types.NullInt{Value: 0, IsSet: false},
   680  						},
   681  						Services: resources.ServiceLimit{
   682  							TotalServiceInstances: &types.NullInt{Value: 0, IsSet: false},
   683  							PaidServicePlans:      &falseValue,
   684  						},
   685  						Routes: resources.RouteLimit{
   686  							TotalRoutes:        &types.NullInt{Value: 0, IsSet: false},
   687  							TotalReservedPorts: &types.NullInt{Value: 0, IsSet: false},
   688  						},
   689  					},
   690  				}
   691  				fakeCloudControllerClient.UpdateOrganizationQuotaReturns(
   692  					ccv3Quota,
   693  					ccv3.Warnings{"update-quota-warning"},
   694  					nil,
   695  				)
   696  			})
   697  
   698  			It("calls the update endpoint with the respective values and returns warnings", func() {
   699  				Expect(fakeCloudControllerClient.UpdateOrganizationQuotaCallCount()).To(Equal(1))
   700  
   701  				Expect(warnings).To(ConsistOf("get-quotas-warning", "update-quota-warning"))
   702  
   703  				passedQuota := fakeCloudControllerClient.UpdateOrganizationQuotaArgsForCall(0)
   704  
   705  				updatedQuota := ccv3Quota
   706  				updatedQuota.Name = newQuotaName
   707  
   708  				Expect(passedQuota).To(Equal(updatedQuota))
   709  			})
   710  		})
   711  
   712  		When("The update org quota endpoint succeeds", func() {
   713  			var (
   714  				ccv3Quota resources.OrganizationQuota
   715  			)
   716  
   717  			BeforeEach(func() {
   718  				ccv3Quota = resources.OrganizationQuota{
   719  					Quota: resources.Quota{
   720  						Name: oldQuotaName,
   721  						Apps: resources.AppLimit{
   722  							TotalMemory:       &types.NullInt{Value: 2048, IsSet: true},
   723  							InstanceMemory:    &types.NullInt{Value: 1024, IsSet: true},
   724  							TotalAppInstances: &types.NullInt{Value: 0, IsSet: false},
   725  						},
   726  						Services: resources.ServiceLimit{
   727  							TotalServiceInstances: &types.NullInt{Value: 0, IsSet: true},
   728  							PaidServicePlans:      &trueValue,
   729  						},
   730  						Routes: resources.RouteLimit{
   731  							TotalRoutes:        &types.NullInt{Value: 6, IsSet: true},
   732  							TotalReservedPorts: &types.NullInt{Value: 5, IsSet: true},
   733  						},
   734  					},
   735  				}
   736  
   737  				fakeCloudControllerClient.UpdateOrganizationQuotaReturns(
   738  					ccv3Quota,
   739  					ccv3.Warnings{"update-quota-warning"},
   740  					nil,
   741  				)
   742  			})
   743  
   744  			It("calls the update endpoint with the respective values and returns warnings", func() {
   745  				Expect(fakeCloudControllerClient.UpdateOrganizationQuotaCallCount()).To(Equal(1))
   746  
   747  				Expect(warnings).To(ConsistOf("get-quotas-warning", "update-quota-warning"))
   748  
   749  				passedQuota := fakeCloudControllerClient.UpdateOrganizationQuotaArgsForCall(0)
   750  
   751  				updatedQuota := ccv3Quota
   752  				updatedQuota.Name = newQuotaName
   753  
   754  				Expect(passedQuota).To(Equal(updatedQuota))
   755  			})
   756  		})
   757  
   758  		When("the org quota name is not being updated", func() {
   759  			var (
   760  				ccv3Quota resources.OrganizationQuota
   761  			)
   762  
   763  			BeforeEach(func() {
   764  				newQuotaName = ""
   765  
   766  				ccv3Quota = resources.OrganizationQuota{
   767  					Quota: resources.Quota{
   768  						Name: oldQuotaName,
   769  						Apps: resources.AppLimit{
   770  							TotalMemory:       &types.NullInt{Value: 2048, IsSet: true},
   771  							InstanceMemory:    &types.NullInt{Value: 1024, IsSet: true},
   772  							TotalAppInstances: &types.NullInt{Value: 0, IsSet: false},
   773  						},
   774  						Services: resources.ServiceLimit{
   775  							TotalServiceInstances: &types.NullInt{Value: 0, IsSet: true},
   776  							PaidServicePlans:      &trueValue,
   777  						},
   778  						Routes: resources.RouteLimit{
   779  							TotalRoutes:        &types.NullInt{Value: 6, IsSet: true},
   780  							TotalReservedPorts: &types.NullInt{Value: 5, IsSet: true},
   781  						},
   782  					},
   783  				}
   784  
   785  				fakeCloudControllerClient.UpdateOrganizationQuotaReturns(
   786  					ccv3Quota,
   787  					ccv3.Warnings{"update-quota-warning"},
   788  					nil,
   789  				)
   790  			})
   791  			It("uses the current org quota name in the API request", func() {
   792  				Expect(executeErr).NotTo(HaveOccurred())
   793  				inputQuota := fakeCloudControllerClient.UpdateOrganizationQuotaArgsForCall(0)
   794  				Expect(inputQuota.Name).To(Equal("old-quota-name"))
   795  			})
   796  		})
   797  	})
   798  })