github.com/lukasheimann/cloudfoundrycli@v7.1.0+incompatible/resources/service_plan_visibility_resource_test.go (about)

     1  package resources_test
     2  
     3  import (
     4  	"encoding/json"
     5  
     6  	. "code.cloudfoundry.org/cli/resources"
     7  	. "github.com/onsi/ginkgo"
     8  	. "github.com/onsi/ginkgo/extensions/table"
     9  	. "github.com/onsi/gomega"
    10  )
    11  
    12  var _ = Describe("service plan visibility resource", func() {
    13  	DescribeTable(
    14  		"Marshaling and Unmarshaling",
    15  		func(servicePlanVisibility ServicePlanVisibility, serialized string) {
    16  			By("marshaling", func() {
    17  				Expect(json.Marshal(servicePlanVisibility)).To(MatchJSON(serialized))
    18  			})
    19  
    20  			By("unmarshaling", func() {
    21  				var parsed ServicePlanVisibility
    22  				Expect(json.Unmarshal([]byte(serialized), &parsed)).NotTo(HaveOccurred())
    23  				Expect(parsed).To(Equal(servicePlanVisibility))
    24  			})
    25  		},
    26  		Entry("public", ServicePlanVisibility{Type: ServicePlanVisibilityPublic}, `{"type": "public"}`),
    27  		Entry("admin", ServicePlanVisibility{Type: ServicePlanVisibilityAdmin}, `{"type": "admin"}`),
    28  		Entry(
    29  			"get space",
    30  			ServicePlanVisibility{
    31  				Type: ServicePlanVisibilitySpace,
    32  				Space: ServicePlanVisibilityDetail{
    33  					Name: "fake-space-name",
    34  					GUID: "fake-space-guid",
    35  				},
    36  			},
    37  			`{
    38  				"type": "space",
    39  				"space": {
    40  					"name": "fake-space-name",
    41  					"guid": "fake-space-guid"
    42  				}
    43              }`,
    44  		),
    45  		Entry(
    46  			"set space",
    47  			ServicePlanVisibility{
    48  				Type:  ServicePlanVisibilitySpace,
    49  				Space: ServicePlanVisibilityDetail{GUID: "fake-space-guid"},
    50  			},
    51  			`{
    52  				"type": "space",
    53  				"space": {"guid": "fake-space-guid"}
    54              }`,
    55  		),
    56  		Entry(
    57  			"get orgs",
    58  			ServicePlanVisibility{
    59  				Type: ServicePlanVisibilityOrganization,
    60  				Organizations: []ServicePlanVisibilityDetail{
    61  					{
    62  						Name: "fake-org-1-name",
    63  						GUID: "fake-org-1-guid",
    64  					},
    65  					{
    66  						Name: "fake-org-2-name",
    67  						GUID: "fake-org-2-guid",
    68  					},
    69  					{
    70  						Name: "fake-org-3-name",
    71  						GUID: "fake-org-3-guid",
    72  					},
    73  				},
    74  			},
    75  			`{
    76  				"type": "organization",
    77  				"organizations": [
    78  					{
    79  						"name": "fake-org-1-name",
    80  						"guid": "fake-org-1-guid"
    81  					},
    82  					{
    83  						"name": "fake-org-2-name",
    84  						"guid": "fake-org-2-guid"
    85  					},
    86  					{
    87  						"name": "fake-org-3-name",
    88  						"guid": "fake-org-3-guid"
    89  					}
    90  				]
    91              }`,
    92  		),
    93  		Entry(
    94  			"set orgs",
    95  			ServicePlanVisibility{
    96  				Type: ServicePlanVisibilityOrganization,
    97  				Organizations: []ServicePlanVisibilityDetail{
    98  					{GUID: "fake-org-1-guid"},
    99  					{GUID: "fake-org-2-guid"},
   100  					{GUID: "fake-org-3-guid"},
   101  				},
   102  			},
   103  			`{
   104  				"type": "organization",
   105  				"organizations": [
   106  					{"guid": "fake-org-1-guid"},
   107  					{"guid": "fake-org-2-guid"},
   108  					{"guid": "fake-org-3-guid"}
   109  				]
   110              }`,
   111  		),
   112  	)
   113  })