github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/api/cloudcontroller/ccv2/space_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("Space Quotas", func() {
    14  	var client *Client
    15  
    16  	BeforeEach(func() {
    17  		client = NewTestClient()
    18  	})
    19  
    20  	Describe("GetSpaceQuotaDefinition", func() {
    21  		Context("when no errors are encountered", func() {
    22  			BeforeEach(func() {
    23  				response := `{
    24  					"metadata": {
    25  						"guid": "space-quota-guid",
    26  						"url": "/v2/space_quota_definitions/space-quota-guid",
    27  						"updated_at": null
    28  					},
    29  					"entity": {
    30  						"name": "space-quota"
    31  					}
    32  				}`
    33  				server.AppendHandlers(
    34  					CombineHandlers(
    35  						VerifyRequest(http.MethodGet, "/v2/space_quota_definitions/space-quota-guid"),
    36  						RespondWith(http.StatusOK, response, http.Header{"X-Cf-Warnings": {"this is a warning"}}),
    37  					),
    38  				)
    39  			})
    40  
    41  			It("returns the Space Quota", func() {
    42  				spaceQuota, warnings, err := client.GetSpaceQuotaDefinition("space-quota-guid")
    43  				Expect(err).NotTo(HaveOccurred())
    44  				Expect(warnings).To(ConsistOf(Warnings{"this is a warning"}))
    45  				Expect(spaceQuota).To(Equal(SpaceQuota{
    46  					Name: "space-quota",
    47  					GUID: "space-quota-guid",
    48  				}))
    49  			})
    50  		})
    51  
    52  		Context("when the request returns an error", func() {
    53  			BeforeEach(func() {
    54  				response := `{
    55  					"code": 210002,
    56  					"description": "The space quota could not be found: some-space-quota-guid",
    57  					"error_code": "CF-AppNotFound"
    58  				}`
    59  				server.AppendHandlers(
    60  					CombineHandlers(
    61  						VerifyRequest(http.MethodGet, "/v2/space_quota_definitions/some-space-quota-guid"),
    62  						RespondWith(http.StatusNotFound, response, http.Header{"X-Cf-Warnings": {"this is a warning"}}),
    63  					),
    64  				)
    65  			})
    66  
    67  			It("returns the error and warnings", func() {
    68  				_, warnings, err := client.GetSpaceQuotaDefinition("some-space-quota-guid")
    69  				Expect(err).To(MatchError(ccerror.ResourceNotFoundError{Message: "The space quota could not be found: some-space-quota-guid"}))
    70  				Expect(warnings).To(ConsistOf(Warnings{"this is a warning"}))
    71  			})
    72  		})
    73  	})
    74  })