github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/api/cloudcontroller/ccv2/service_instance_shared_from_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 Instance Shared From", func() {
    14  	var (
    15  		client *Client
    16  
    17  		serviceInstance ServiceInstanceSharedFrom
    18  		warnings        Warnings
    19  		err             error
    20  	)
    21  
    22  	BeforeEach(func() {
    23  		client = NewTestClient()
    24  	})
    25  
    26  	JustBeforeEach(func() {
    27  		serviceInstance, warnings, err = client.GetServiceInstanceSharedFrom("some-service-instance-guid")
    28  	})
    29  
    30  	Describe("GetServiceInstanceSharedFrom", func() {
    31  		Context("when the cc api returns no errors", func() {
    32  			Context("when the response is not an http 204", func() {
    33  				BeforeEach(func() {
    34  					response1 := `{
    35  			  "space_guid": "some-space-guid",
    36  				"space_name": "some-space-name",
    37  			  "organization_name": "some-org-name"
    38  		 }`
    39  
    40  					server.AppendHandlers(
    41  						CombineHandlers(
    42  							VerifyRequest(http.MethodGet, "/v2/service_instances/some-service-instance-guid/shared_from"),
    43  							RespondWith(http.StatusOK, response1, http.Header{"X-Cf-Warnings": {"this is a warning"}}),
    44  						),
    45  					)
    46  				})
    47  
    48  				It("returns all the shared_from resources", func() {
    49  					Expect(err).NotTo(HaveOccurred())
    50  
    51  					Expect(serviceInstance).To(Equal(ServiceInstanceSharedFrom{
    52  						SpaceGUID:        "some-space-guid",
    53  						SpaceName:        "some-space-name",
    54  						OrganizationName: "some-org-name",
    55  					}))
    56  					Expect(warnings).To(ConsistOf(Warnings{"this is a warning"}))
    57  				})
    58  			})
    59  
    60  			Context("when the response is an http 204", func() {
    61  				BeforeEach(func() {
    62  					server.AppendHandlers(
    63  						CombineHandlers(
    64  							VerifyRequest(http.MethodGet, "/v2/service_instances/some-service-instance-guid/shared_from"),
    65  							RespondWith(http.StatusNoContent, "", http.Header{"X-Cf-Warnings": {"this is a warning"}}),
    66  						),
    67  					)
    68  				})
    69  
    70  				It("returns an empty ServiceInstanceSharedFrom and no error", func() {
    71  					Expect(err).NotTo(HaveOccurred())
    72  					Expect(serviceInstance).To(Equal(ServiceInstanceSharedFrom{}))
    73  					Expect(warnings).To(ConsistOf(Warnings{"this is a warning"}))
    74  				})
    75  			})
    76  		})
    77  
    78  		Context("when the cc api encounters an error", func() {
    79  			BeforeEach(func() {
    80  				response := `{
    81  					"code": 10001,
    82  					"description": "Some Error",
    83  					"error_code": "CF-SomeError"
    84  				}`
    85  				server.AppendHandlers(
    86  					CombineHandlers(
    87  						VerifyRequest(http.MethodGet, "/v2/service_instances/some-service-instance-guid/shared_from"),
    88  						RespondWith(http.StatusTeapot, response, http.Header{"X-Cf-Warnings": {"warning-1, warning-2"}}),
    89  					))
    90  			})
    91  
    92  			It("returns an error and warnings", func() {
    93  				Expect(err).To(MatchError(ccerror.V2UnexpectedResponseError{
    94  					ResponseCode: http.StatusTeapot,
    95  					V2ErrorResponse: ccerror.V2ErrorResponse{
    96  						Code:        10001,
    97  						Description: "Some Error",
    98  						ErrorCode:   "CF-SomeError",
    99  					},
   100  				}))
   101  				Expect(warnings).To(ConsistOf("warning-1", "warning-2"))
   102  			})
   103  		})
   104  	})
   105  })