github.com/Thanhphan1147/cloudfoundry-cli@v7.1.0+incompatible/resources/service_instance_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 instance resource", func() {
    13  	DescribeTable(
    14  		"Marshaling and Unmarshaling",
    15  		func(serviceInstance ServiceInstance, serialized string) {
    16  			By("marshaling", func() {
    17  				Expect(json.Marshal(serviceInstance)).To(MatchJSON(serialized))
    18  			})
    19  
    20  			By("unmarshaling", func() {
    21  				var parsed ServiceInstance
    22  				Expect(json.Unmarshal([]byte(serialized), &parsed)).NotTo(HaveOccurred())
    23  				Expect(parsed).To(Equal(serviceInstance))
    24  			})
    25  		},
    26  		Entry("type", ServiceInstance{Type: "fake-type"}, `{"type": "fake-type"}`),
    27  		Entry("name", ServiceInstance{Name: "fake-name"}, `{"name": "fake-name"}`),
    28  		Entry("guid", ServiceInstance{GUID: "fake-guid"}, `{"guid": "fake-guid"}`),
    29  		Entry(
    30  			"space guid",
    31  			ServiceInstance{SpaceGUID: "fake-space-guid"},
    32  			`{
    33  				"relationships": {
    34  					"space": {
    35  						"data": {
    36  							"guid": "fake-space-guid"
    37  						}
    38  					}
    39  				}
    40              }`,
    41  		),
    42  		Entry(
    43  			"everything",
    44  			ServiceInstance{
    45  				Type:      UserProvidedServiceInstance,
    46  				GUID:      "fake-guid",
    47  				Name:      "fake-space-guid",
    48  				SpaceGUID: "fake-space-guid",
    49  			},
    50  			`{
    51  				"type": "user-provided",
    52  				"guid": "fake-guid",
    53  				"name": "fake-space-guid",
    54  				"relationships": {
    55  					"space": {
    56  						"data": {
    57  							"guid": "fake-space-guid"
    58  						}
    59  					}
    60  				}
    61              }`,
    62  		),
    63  	)
    64  })