github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/api/cloudcontroller/ccv2/service_plan_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("Service Plan", func() {
    14  	var client *Client
    15  
    16  	BeforeEach(func() {
    17  		client = NewTestClient()
    18  	})
    19  
    20  	Describe("GetServicePlan", func() {
    21  		Context("when the service plan exists", func() {
    22  			BeforeEach(func() {
    23  				response := `{
    24  					"metadata": {
    25  						"guid": "some-service-plan-guid"
    26  					},
    27  					"entity": {
    28  						"name": "some-service-plan",
    29  						"service_guid": "some-service-guid"
    30  					}
    31  				}`
    32  
    33  				server.AppendHandlers(
    34  					CombineHandlers(
    35  						VerifyRequest(http.MethodGet, "/v2/service_plans/some-service-plan-guid"),
    36  						RespondWith(http.StatusOK, response, http.Header{"X-Cf-Warnings": {"this is a warning"}}),
    37  					),
    38  				)
    39  			})
    40  
    41  			It("returns the service plan and warnings", func() {
    42  				servicePlan, warnings, err := client.GetServicePlan("some-service-plan-guid")
    43  				Expect(err).NotTo(HaveOccurred())
    44  
    45  				Expect(servicePlan).To(Equal(ServicePlan{
    46  					GUID:        "some-service-plan-guid",
    47  					Name:        "some-service-plan",
    48  					ServiceGUID: "some-service-guid",
    49  				}))
    50  				Expect(warnings).To(ConsistOf(Warnings{"this is a warning"}))
    51  			})
    52  		})
    53  
    54  		Context("when the service plan does not exist (testing general error case)", func() {
    55  			BeforeEach(func() {
    56  				response := `{
    57  					"description": "The service plan could not be found: non-existant-service-plan-guid",
    58  					"error_code": "CF-ServicePlanNotFound",
    59  					"code": 110003
    60  				}`
    61  
    62  				server.AppendHandlers(
    63  					CombineHandlers(
    64  						VerifyRequest(http.MethodGet, "/v2/service_plans/non-existant-service-plan-guid"),
    65  						RespondWith(http.StatusNotFound, response, http.Header{"X-Cf-Warnings": {"this is a warning"}}),
    66  					))
    67  			})
    68  
    69  			It("returns an error and warnings", func() {
    70  				_, warnings, err := client.GetServicePlan("non-existant-service-plan-guid")
    71  				Expect(err).To(MatchError(ccerror.ResourceNotFoundError{Message: "The service plan could not be found: non-existant-service-plan-guid"}))
    72  				Expect(warnings).To(ConsistOf(Warnings{"this is a warning"}))
    73  			})
    74  		})
    75  	})
    76  })