github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/api/cloudcontroller/ccv2/service_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", func() {
    14  	var client *Client
    15  
    16  	BeforeEach(func() {
    17  		client = NewTestClient()
    18  	})
    19  
    20  	Describe("GetService", func() {
    21  		Context("when the service exists", func() {
    22  			BeforeEach(func() {
    23  				response := `{
    24  					"metadata": {
    25  						"guid": "some-service-guid"
    26  					},
    27  					"entity": {
    28  						"label": "some-service",
    29  						"description": "some-description",
    30  						"documentation_url": "some-url",
    31  						"extra": "{\"provider\":{\"name\":\"The name\"},\"listing\":{\"imageUrl\":\"http://catgifpage.com/cat.gif\",\"blurb\":\"fake broker that is fake\",\"longDescription\":\"A long time ago, in a galaxy far far away...\"},\"displayName\":\"The Fake Broker\",\"shareable\":true}"
    32  					}
    33  				}`
    34  
    35  				server.AppendHandlers(
    36  					CombineHandlers(
    37  						VerifyRequest(http.MethodGet, "/v2/services/some-service-guid"),
    38  						RespondWith(http.StatusOK, response, http.Header{"X-Cf-Warnings": {"this is a warning"}}),
    39  					),
    40  				)
    41  			})
    42  
    43  			It("returns the service and warnings", func() {
    44  				service, warnings, err := client.GetService("some-service-guid")
    45  				Expect(err).NotTo(HaveOccurred())
    46  
    47  				Expect(service).To(Equal(Service{
    48  					GUID:             "some-service-guid",
    49  					Label:            "some-service",
    50  					Description:      "some-description",
    51  					DocumentationURL: "some-url",
    52  					Extra: ServiceExtra{
    53  						Shareable: true,
    54  					},
    55  				}))
    56  				Expect(warnings).To(ConsistOf(Warnings{"this is a warning"}))
    57  			})
    58  		})
    59  
    60  		Context("when the service does not exist (testing general error case)", func() {
    61  			BeforeEach(func() {
    62  				response := `{
    63  					"description": "The service could not be found: non-existant-service-guid",
    64  					"error_code": "CF-ServiceNotFound",
    65  					"code": 120003
    66  				}`
    67  
    68  				server.AppendHandlers(
    69  					CombineHandlers(
    70  						VerifyRequest(http.MethodGet, "/v2/services/non-existant-service-guid"),
    71  						RespondWith(http.StatusNotFound, response, http.Header{"X-Cf-Warnings": {"this is a warning"}}),
    72  					))
    73  			})
    74  
    75  			It("returns an error and warnings", func() {
    76  				_, warnings, err := client.GetService("non-existant-service-guid")
    77  				Expect(err).To(MatchError(ccerror.ResourceNotFoundError{Message: "The service could not be found: non-existant-service-guid"}))
    78  				Expect(warnings).To(ConsistOf(Warnings{"this is a warning"}))
    79  			})
    80  		})
    81  	})
    82  })