github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/api/cloudcontroller/ccv2/organization_quota_test.go (about)

     1  package ccv2_test
     2  
     3  import (
     4  	"net/http"
     5  
     6  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccerror"
     7  	. "code.cloudfoundry.org/cli/api/cloudcontroller/ccv2"
     8  	. "github.com/onsi/ginkgo"
     9  	. "github.com/onsi/gomega"
    10  	. "github.com/onsi/gomega/ghttp"
    11  )
    12  
    13  var _ = Describe("OrganizationQuota", func() {
    14  	var client *Client
    15  
    16  	BeforeEach(func() {
    17  		client = NewTestClient()
    18  	})
    19  
    20  	Describe("GetOrganizationQuota", func() {
    21  
    22  		Context("when getting the organization quota does not return an error", func() {
    23  			BeforeEach(func() {
    24  				response := `{
    25  				"metadata": {
    26  					"guid": "some-org-quota-guid"
    27  				},
    28  				"entity": {
    29  					"name": "some-org-quota"
    30  				}
    31  			}`
    32  				server.AppendHandlers(
    33  					CombineHandlers(
    34  						VerifyRequest(http.MethodGet, "/v2/quota_definitions/some-org-quota-guid"),
    35  						RespondWith(http.StatusOK, response, http.Header{"X-Cf-Warnings": {"warning-1"}}),
    36  					),
    37  				)
    38  			})
    39  
    40  			It("returns the organization quota", func() {
    41  				orgQuota, warnings, err := client.GetOrganizationQuota("some-org-quota-guid")
    42  				Expect(err).NotTo(HaveOccurred())
    43  				Expect(warnings).To(Equal(Warnings{"warning-1"}))
    44  				Expect(orgQuota).To(Equal(OrganizationQuota{
    45  					GUID: "some-org-quota-guid",
    46  					Name: "some-org-quota",
    47  				}))
    48  			})
    49  		})
    50  
    51  		Context("when the organization quota returns an error", func() {
    52  			BeforeEach(func() {
    53  				response := `{
    54  				  "description": "Quota Definition could not be found: some-org-quota-guid",
    55  				  "error_code": "CF-QuotaDefinitionNotFound",
    56  				  "code": 240001
    57  				}`
    58  				server.AppendHandlers(
    59  					CombineHandlers(
    60  						VerifyRequest(http.MethodGet, "/v2/quota_definitions/some-org-quota-guid"),
    61  						RespondWith(http.StatusNotFound, response, http.Header{"X-Cf-Warnings": {"warning-1"}}),
    62  					),
    63  				)
    64  			})
    65  
    66  			It("returns the error", func() {
    67  				_, warnings, err := client.GetOrganizationQuota("some-org-quota-guid")
    68  				Expect(err).To(MatchError(ccerror.ResourceNotFoundError{
    69  					Message: "Quota Definition could not be found: some-org-quota-guid",
    70  				}))
    71  				Expect(warnings).To(Equal(Warnings{"warning-1"}))
    72  			})
    73  		})
    74  
    75  	})
    76  })