github.com/DaAlbrecht/cf-cli@v0.0.0-20231128151943-1fe19bb400b9/resources/shared_to_spaces_resource_test.go (about) 1 package resources_test 2 3 import ( 4 "encoding/json" 5 6 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant" 7 8 . "code.cloudfoundry.org/cli/resources" 9 . "github.com/onsi/ginkgo" 10 . "github.com/onsi/ginkgo/extensions/table" 11 . "github.com/onsi/gomega" 12 ) 13 14 var _ = Describe("shared to spaces resource", func() { 15 DescribeTable( 16 "Unmarshaling", 17 func(sharedToSpaces SharedToSpacesListWrapper, serialized string) { 18 var parsed SharedToSpacesListWrapper 19 Expect(json.Unmarshal([]byte(serialized), &parsed)).NotTo(HaveOccurred()) 20 Expect(parsed).To(Equal(sharedToSpaces)) 21 }, 22 Entry("SharedToSpaceGUIDs", SharedToSpacesListWrapper{SharedToSpaceGUIDs: []string{"fake-space-guid", "other-fake-space-guid"}}, `{"data": [{"guid": "fake-space-guid"}, {"guid": "other-fake-space-guid"}]}`), 23 Entry("Spaces", SharedToSpacesListWrapper{ 24 Spaces: []Space{ 25 { 26 GUID: "fake-space-guid", 27 Name: "fake-space-name", 28 Relationships: map[constant.RelationshipType]Relationship{ 29 "organization": Relationship{ 30 GUID: "some-org-guid", 31 }, 32 }, 33 }, 34 }, 35 }, `{ 36 "included": { 37 "spaces": [ 38 { 39 "name": "fake-space-name", 40 "guid": "fake-space-guid", 41 "relationships": { 42 "organization": { 43 "data": { 44 "guid": "some-org-guid" 45 } 46 } 47 } 48 } 49 ] 50 } 51 }`), 52 Entry("Organizations", SharedToSpacesListWrapper{ 53 Organizations: []Organization{ 54 { 55 GUID: "fake-org-guid", 56 Name: "fake-org-name", 57 }, 58 }, 59 }, `{ 60 "included": { 61 "organizations": [ 62 { 63 "name": "fake-org-name", 64 "guid": "fake-org-guid" 65 } 66 ] 67 } 68 }`), 69 Entry( 70 "everything", 71 SharedToSpacesListWrapper{ 72 SharedToSpaceGUIDs: []string{"fake-space-guid", "other-fake-space-guid"}, 73 Spaces: []Space{ 74 { 75 GUID: "fake-space-guid", 76 Name: "fake-space-name", 77 Relationships: map[constant.RelationshipType]Relationship{"organization": Relationship{GUID: "fake-org-guid"}}}, 78 { 79 GUID: "other-fake-space-guid", 80 Name: "other-fake-space-name", 81 Relationships: map[constant.RelationshipType]Relationship{"organization": Relationship{GUID: "fake-org-guid"}}}}, 82 Organizations: []Organization{ 83 { 84 GUID: "fake-org-guid", 85 Name: "fake-org-name", 86 }, 87 }}, 88 89 `{ 90 "data": [{"guid":"fake-space-guid"},{"guid":"other-fake-space-guid"}], 91 "links": { 92 "self": { 93 "href": "https://some-url/v3/service_instances/7915bc51-8203-4758-b0e2-f77bfcdc38cb/relationships/shared_spaces" 94 } 95 }, 96 "included": { 97 "spaces": [ 98 { 99 "name": "fake-space-name", 100 "guid": "fake-space-guid", 101 "relationships": { 102 "organization": { 103 "data": { 104 "guid": "fake-org-guid" 105 } 106 } 107 } 108 }, 109 { 110 "name": "other-fake-space-name", 111 "guid": "other-fake-space-guid", 112 "relationships": { 113 "organization": { 114 "data": { 115 "guid": "fake-org-guid" 116 } 117 } 118 } 119 } 120 ], 121 "organizations": [ 122 { 123 "name": "fake-org-name", 124 "guid": "fake-org-guid" 125 } 126 ] 127 } 128 }`, 129 ), 130 ) 131 })