github.com/cloudfoundry-attic/cli-with-i18n@v6.32.1-0.20171002233121-7401370d3b85+incompatible/api/cloudcontroller/ccv3/relationship_list_test.go (about)

     1  package ccv3_test
     2  
     3  import (
     4  	"net/http"
     5  
     6  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccerror"
     7  	. "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3"
     8  	. "github.com/onsi/ginkgo"
     9  	. "github.com/onsi/gomega"
    10  	. "github.com/onsi/gomega/ghttp"
    11  )
    12  
    13  var _ = Describe("RelationshipList", func() {
    14  	var (
    15  		client *Client
    16  	)
    17  
    18  	BeforeEach(func() {
    19  		client = NewTestClient()
    20  	})
    21  
    22  	Describe("EntitleIsolationSegmentToOrganizations", func() {
    23  		Context("when the delete is successful", func() {
    24  			BeforeEach(func() {
    25  				response := `{
    26  					"data": [
    27  						{
    28  							"guid": "some-relationship-guid-1"
    29  						},
    30  						{
    31  							"guid": "some-relationship-guid-2"
    32  						}
    33  					]
    34  				}`
    35  
    36  				requestBody := map[string][]map[string]string{
    37  					"data": {{"guid": "org-guid-1"}, {"guid": "org-guid-2"}},
    38  				}
    39  				server.AppendHandlers(
    40  					CombineHandlers(
    41  						VerifyRequest(http.MethodPost, "/v3/isolation_segments/some-iso-guid/relationships/organizations"),
    42  						VerifyJSONRepresenting(requestBody),
    43  						RespondWith(http.StatusOK, response, http.Header{"X-Cf-Warnings": {"this is a warning"}}),
    44  					),
    45  				)
    46  			})
    47  
    48  			It("returns all relationships and warnings", func() {
    49  				relationships, warnings, err := client.EntitleIsolationSegmentToOrganizations("some-iso-guid", []string{"org-guid-1", "org-guid-2"})
    50  				Expect(err).NotTo(HaveOccurred())
    51  				Expect(warnings).To(ConsistOf("this is a warning"))
    52  				Expect(relationships).To(Equal(RelationshipList{
    53  					GUIDs: []string{"some-relationship-guid-1", "some-relationship-guid-2"},
    54  				}))
    55  			})
    56  		})
    57  
    58  		Context("when the cloud controller returns errors and warnings", func() {
    59  			BeforeEach(func() {
    60  				response := `{
    61  					"errors": [
    62  						{
    63  							"code": 10008,
    64  							"detail": "The request is semantically invalid: command presence",
    65  							"title": "CF-UnprocessableEntity"
    66  						}
    67  					]
    68  				}`
    69  				server.AppendHandlers(
    70  					CombineHandlers(
    71  						VerifyRequest(http.MethodPost, "/v3/isolation_segments/some-iso-guid/relationships/organizations"),
    72  						RespondWith(http.StatusTeapot, response, http.Header{"X-Cf-Warnings": {"this is a warning"}}),
    73  					),
    74  				)
    75  			})
    76  
    77  			It("returns the error and all warnings", func() {
    78  				_, warnings, err := client.EntitleIsolationSegmentToOrganizations("some-iso-guid", []string{"org-guid-1", "org-guid-2"})
    79  				Expect(err).To(MatchError(ccerror.V3UnexpectedResponseError{
    80  					ResponseCode: http.StatusTeapot,
    81  					V3ErrorResponse: ccerror.V3ErrorResponse{
    82  						Errors: []ccerror.V3Error{
    83  							{
    84  								Code:   10008,
    85  								Detail: "The request is semantically invalid: command presence",
    86  								Title:  "CF-UnprocessableEntity",
    87  							},
    88  						},
    89  					},
    90  				}))
    91  				Expect(warnings).To(ConsistOf("this is a warning"))
    92  			})
    93  		})
    94  	})
    95  })