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