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

     1  package resources_test
     2  
     3  import (
     4  	"encoding/json"
     5  
     6  	. "code.cloudfoundry.org/cli/resources"
     7  	"code.cloudfoundry.org/cli/types"
     8  	. "github.com/onsi/ginkgo"
     9  	. "github.com/onsi/ginkgo/extensions/table"
    10  	. "github.com/onsi/gomega"
    11  )
    12  
    13  var _ = Describe("service broker resource", func() {
    14  	DescribeTable(
    15  		"Marshaling and Unmarshaling",
    16  		func(serviceInstance ServiceBroker, serialized string) {
    17  			By("marshaling", func() {
    18  				Expect(json.Marshal(serviceInstance)).To(MatchJSON(serialized))
    19  			})
    20  
    21  			By("unmarshaling", func() {
    22  				var parsed ServiceBroker
    23  				Expect(json.Unmarshal([]byte(serialized), &parsed)).NotTo(HaveOccurred())
    24  				Expect(parsed).To(Equal(serviceInstance))
    25  			})
    26  		},
    27  		Entry("name", ServiceBroker{Name: "fake-name"}, `{"name": "fake-name"}`),
    28  		Entry("guid", ServiceBroker{GUID: "fake-guid"}, `{"guid": "fake-guid"}`),
    29  		Entry("url", ServiceBroker{URL: "https://fake-url.com"}, `{"url": "https://fake-url.com"}`),
    30  		Entry(
    31  			"space guid",
    32  			ServiceBroker{SpaceGUID: "fake-space-guid"},
    33  			`{
    34  				"relationships": {
    35  					"space": {
    36  						"data": {
    37  							"guid": "fake-space-guid"
    38  						}
    39  					}
    40  				}
    41              }`,
    42  		),
    43  		Entry(
    44  			"authentication",
    45  			ServiceBroker{
    46  				CredentialsType: ServiceBrokerBasicCredentials,
    47  				Username:        "fake-username",
    48  				Password:        "fake-password",
    49  			},
    50  			`{
    51  				"authentication": {
    52  					"type": "basic",
    53  					"credentials": {
    54  						"username": "fake-username",
    55  						"password": "fake-password"
    56  					}
    57  				}
    58  			}`,
    59  		),
    60  		Entry(
    61  			"metadata",
    62  			ServiceBroker{
    63  				Metadata: &Metadata{
    64  					Labels: map[string]types.NullString{
    65  						"foo": types.NewNullString("bar"),
    66  						"baz": types.NewNullString(),
    67  					},
    68  				},
    69  			},
    70  			`{
    71  				"metadata": {
    72  					"labels": {
    73  						"foo": "bar",
    74  						"baz": null
    75  					}
    76  				}
    77  			}`,
    78  		),
    79  		Entry(
    80  			"everything",
    81  			ServiceBroker{
    82  				Name:            "fake-name",
    83  				GUID:            "fake-guid",
    84  				URL:             "https://fake-url.com",
    85  				SpaceGUID:       "fake-space-guid",
    86  				CredentialsType: ServiceBrokerBasicCredentials,
    87  				Username:        "fake-username",
    88  				Password:        "fake-password",
    89  				Metadata: &Metadata{
    90  					Labels: map[string]types.NullString{
    91  						"foo": types.NewNullString("bar"),
    92  						"baz": types.NewNullString(),
    93  					},
    94  				},
    95  			},
    96  			`{
    97  				"name": "fake-name",
    98  				"guid": "fake-guid",
    99  				"url": "https://fake-url.com",
   100  				"authentication": {
   101  					"type": "basic",
   102  					"credentials": {
   103  						"username": "fake-username",
   104  						"password": "fake-password"
   105  					}
   106  				},
   107  				"metadata": {
   108  					"labels": {
   109  						"foo": "bar",
   110  						"baz": null
   111  					}
   112  				},
   113  				"relationships": {
   114  					"space": {
   115  						"data": {
   116  							"guid": "fake-space-guid"
   117  						}
   118  					}
   119  				}
   120              }`,
   121  		),
   122  	)
   123  })