github.com/DaAlbrecht/cf-cli@v0.0.0-20231128151943-1fe19bb400b9/resources/service_credential_binding_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 credential binding resource", func() {
    14  	DescribeTable(
    15  		"Marshaling and Unmarshaling",
    16  		func(binding ServiceCredentialBinding, serialized string) {
    17  			By("marshaling", func() {
    18  				Expect(json.Marshal(binding)).To(MatchJSON(serialized))
    19  			})
    20  
    21  			By("unmarshaling", func() {
    22  				var parsed ServiceCredentialBinding
    23  				Expect(json.Unmarshal([]byte(serialized), &parsed)).NotTo(HaveOccurred())
    24  				Expect(parsed).To(Equal(binding))
    25  			})
    26  		},
    27  		Entry("empty", ServiceCredentialBinding{}, `{}`),
    28  		Entry("type", ServiceCredentialBinding{Type: "fake-type"}, `{"type": "fake-type"}`),
    29  		Entry("name", ServiceCredentialBinding{Name: "fake-name"}, `{"name": "fake-name"}`),
    30  		Entry("guid", ServiceCredentialBinding{GUID: "fake-guid"}, `{"guid": "fake-guid"}`),
    31  		Entry("service instance guid guid",
    32  			ServiceCredentialBinding{ServiceInstanceGUID: "fake-instance-guid"},
    33  			`{ "relationships": { "service_instance": { "data": { "guid": "fake-instance-guid" } } } }`,
    34  		),
    35  		Entry("app guid",
    36  			ServiceCredentialBinding{AppGUID: "fake-app-guid"},
    37  			`{ "relationships": { "app": { "data": { "guid": "fake-app-guid" } } } }`,
    38  		),
    39  		Entry(
    40  			"last operation",
    41  			ServiceCredentialBinding{
    42  				LastOperation: LastOperation{Type: CreateOperation, State: OperationInProgress},
    43  			},
    44  			`{
    45  				"last_operation": {
    46  					"type": "create",
    47  					"state": "in progress"
    48  				}
    49  			}`,
    50  		),
    51  		Entry(
    52  			"parameters",
    53  			ServiceCredentialBinding{
    54  				Parameters: types.NewOptionalObject(map[string]interface{}{
    55  					"foo": "bar",
    56  				}),
    57  			},
    58  			`{
    59  				"parameters": {
    60  					"foo": "bar"
    61  				}
    62  			}`,
    63  		),
    64  		Entry(
    65  			"everything",
    66  			ServiceCredentialBinding{
    67  				Type:                AppBinding,
    68  				GUID:                "fake-guid",
    69  				Name:                "fake-name",
    70  				AppGUID:             "fake-app-guid",
    71  				ServiceInstanceGUID: "fake-service-instance-guid",
    72  				Parameters: types.NewOptionalObject(map[string]interface{}{
    73  					"foo": "bar",
    74  				}),
    75  			},
    76  			`{
    77  				"type": "app",
    78  				"guid": "fake-guid",
    79  				"name": "fake-name",
    80  				"relationships": {
    81  					"service_instance": {
    82  						"data": {
    83  							"guid": "fake-service-instance-guid"
    84  						}
    85  					},
    86  					"app": {
    87  						"data": {
    88  							"guid": "fake-app-guid"
    89  						}
    90  					}
    91  				},
    92  				"parameters": {
    93  					"foo": "bar"
    94  				}
    95  			}`,
    96  		),
    97  	)
    98  })