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