github.com/DaAlbrecht/cf-cli@v0.0.0-20231128151943-1fe19bb400b9/resources/route_binding_test.go (about)

     1  package resources
     2  
     3  import (
     4  	"encoding/json"
     5  
     6  	"code.cloudfoundry.org/cli/types"
     7  	. "github.com/onsi/ginkgo"
     8  	. "github.com/onsi/ginkgo/extensions/table"
     9  	. "github.com/onsi/gomega"
    10  )
    11  
    12  var _ = Describe("RouteBinding", func() {
    13  	DescribeTable(
    14  		"Marshaling and Unmarshaling",
    15  		func(binding RouteBinding, serialized string) {
    16  			By("marshalling", func() {
    17  				Expect(json.Marshal(binding)).To(MatchJSON(serialized))
    18  			})
    19  
    20  			By("unmarshaling", func() {
    21  				var parsed RouteBinding
    22  				Expect(json.Unmarshal([]byte(serialized), &parsed)).NotTo(HaveOccurred())
    23  				Expect(parsed).To(Equal(binding))
    24  			})
    25  		},
    26  		Entry("empty", RouteBinding{}, `{}`),
    27  		Entry("guid", RouteBinding{GUID: "fake-guid"}, `{"guid": "fake-guid"}`),
    28  		Entry("route service url", RouteBinding{RouteServiceURL: "fake-route-service-url"}, `{"route_service_url": "fake-route-service-url"}`),
    29  		Entry(
    30  			"route guid",
    31  			RouteBinding{RouteGUID: "fake-route-guid"},
    32  			`{
    33  				"relationships": {
    34  					"route": {
    35  						"data": {
    36  							"guid": "fake-route-guid"
    37  						}
    38  					}
    39  				}
    40  			}`,
    41  		),
    42  		Entry(
    43  			"service instance guid",
    44  			RouteBinding{ServiceInstanceGUID: "fake-service-instance-guid"},
    45  			`{
    46  				"relationships": {
    47  					"service_instance": {
    48  						"data": {
    49  							"guid": "fake-service-instance-guid"
    50  						}
    51  					}
    52  				}
    53  			}`,
    54  		),
    55  		Entry(
    56  			"parameters",
    57  			RouteBinding{
    58  				Parameters: types.NewOptionalObject(map[string]interface{}{
    59  					"foo": "bar",
    60  				}),
    61  			},
    62  			`{
    63  				"parameters": {
    64  					"foo": "bar"
    65  				}
    66  			}`,
    67  		),
    68  		Entry(
    69  			"last operation",
    70  			RouteBinding{
    71  				LastOperation: LastOperation{
    72  					Type:        "fake-operation-type",
    73  					State:       "fake-operation-state",
    74  					Description: "fake-operation-description",
    75  				},
    76  			},
    77  			`{
    78  				"last_operation": {
    79  					"type": "fake-operation-type",
    80  					"state": "fake-operation-state",
    81  					"description": "fake-operation-description"
    82  				}
    83  			}`,
    84  		),
    85  		Entry(
    86  			"complete",
    87  			RouteBinding{
    88  				GUID:                "fake-guid",
    89  				RouteServiceURL:     "fake-route-service-url",
    90  				ServiceInstanceGUID: "fake-service-instance-guid",
    91  				RouteGUID:           "fake-route-guid",
    92  				LastOperation: LastOperation{
    93  					Type:        "fake-operation-type",
    94  					State:       "fake-operation-state",
    95  					Description: "fake-operation-description",
    96  				},
    97  				Parameters: types.NewOptionalObject(map[string]interface{}{
    98  					"foo": "bar",
    99  				}),
   100  			},
   101  			`{
   102  				"guid": "fake-guid",
   103  				"route_service_url": "fake-route-service-url",
   104  				"parameters": {"foo": "bar"},
   105  				"last_operation": {
   106  					"type": "fake-operation-type",
   107  					"state": "fake-operation-state",
   108  					"description": "fake-operation-description"
   109  				},
   110  				"relationships": {
   111  					"service_instance": {
   112  						"data": {
   113  							"guid": "fake-service-instance-guid"
   114  						}
   115  					},
   116  					"route": {
   117  						"data": {
   118  							"guid": "fake-route-guid"
   119  						}
   120  					}
   121  				}
   122  			}`,
   123  		),
   124  	)
   125  })