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

     1  package ccv2_test
     2  
     3  import (
     4  	"net/http"
     5  
     6  	. "code.cloudfoundry.org/cli/api/cloudcontroller/ccv2"
     7  	. "github.com/onsi/ginkgo"
     8  	. "github.com/onsi/gomega"
     9  	. "github.com/onsi/gomega/ghttp"
    10  )
    11  
    12  var _ = Describe("Service Instance Shared To", func() {
    13  	var client *Client
    14  
    15  	BeforeEach(func() {
    16  		client = NewTestClient()
    17  	})
    18  
    19  	Describe("GetServiceInstanceSharedTos", func() {
    20  		Context("when the cc api returns a valid response", func() {
    21  			BeforeEach(func() {
    22  				response1 := `{
    23  				"total_results": 3,
    24  				"total_pages": 2,
    25  				"prev_url": null,
    26  				"next_url": "/v2/service_instances/some-service-instance-guid/shared_to?page=2",
    27  				"resources": [{
    28  						"space_guid": "some-space-guid",
    29  						"space_name": "some-space-name",
    30  						"organization_name": "some-org-name"
    31  					},
    32  					{
    33  						"space_guid": "some-space-guid-2",
    34  						"space_name": "some-space-name-2",
    35  						"organization_name": "some-org-name-2"
    36  					}
    37  				]
    38  			}`
    39  
    40  				response2 := `{
    41  				"total_results": 3,
    42  				"total_pages": 2,
    43  				"prev_url": "/v2/service_instances/some-service-instance-guid/shared_to?page=1",
    44  				"next_url": null,
    45  				"resources": [{
    46  					"space_guid": "some-space-guid-3",
    47  					"space_name": "some-space-name-3",
    48  					"organization_name": "some-org-name-3"
    49  				}]
    50  			}`
    51  
    52  				server.AppendHandlers(
    53  					CombineHandlers(
    54  						VerifyRequest(http.MethodGet, "/v2/service_instances/some-service-instance-guid/shared_to"),
    55  						RespondWith(http.StatusOK, response1, http.Header{"X-Cf-Warnings": {"this is a warning"}}),
    56  					),
    57  				)
    58  
    59  				server.AppendHandlers(
    60  					CombineHandlers(
    61  						VerifyRequest(http.MethodGet, "/v2/service_instances/some-service-instance-guid/shared_to", "page=2"),
    62  						RespondWith(http.StatusOK, response2, http.Header{"X-Cf-Warnings": {"this is another warning"}}),
    63  					),
    64  				)
    65  			})
    66  
    67  			Context("when the service instance exist", func() {
    68  				It("returns all the shared-to resources", func() {
    69  					serviceInstances, warnings, err := client.GetServiceInstanceSharedTos("some-service-instance-guid")
    70  					Expect(err).NotTo(HaveOccurred())
    71  
    72  					Expect(serviceInstances).To(ConsistOf([]ServiceInstanceSharedTo{
    73  						{SpaceGUID: "some-space-guid", SpaceName: "some-space-name", OrganizationName: "some-org-name"},
    74  						{SpaceGUID: "some-space-guid-2", SpaceName: "some-space-name-2", OrganizationName: "some-org-name-2"},
    75  						{SpaceGUID: "some-space-guid-3", SpaceName: "some-space-name-3", OrganizationName: "some-org-name-3"},
    76  					}))
    77  					Expect(warnings).To(ConsistOf(Warnings{"this is a warning", "this is another warning"}))
    78  				})
    79  			})
    80  		})
    81  
    82  		Context("when the cc api returns an invalid response", func() {
    83  			BeforeEach(func() {
    84  				invalidResponse := `{"foo": "bar"}`
    85  
    86  				server.AppendHandlers(
    87  					CombineHandlers(
    88  						VerifyRequest(http.MethodGet, "/v2/service_instances/some-service-instance-guid/shared_to"),
    89  						RespondWith(http.StatusOK, invalidResponse, http.Header{"X-Cf-Warnings": {"this is a warning"}}),
    90  					),
    91  				)
    92  			})
    93  
    94  			It("returns an error and warnings", func() {
    95  				_, warnings, err := client.GetServiceInstanceSharedTos("some-service-instance-guid")
    96  				Expect(err).To(HaveOccurred())
    97  				Expect(warnings).To(ConsistOf(Warnings{"this is a warning"}))
    98  			})
    99  		})
   100  	})
   101  })