github.com/DaAlbrecht/cf-cli@v0.0.0-20231128151943-1fe19bb400b9/resources/service_plan_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 plan resource", func() {
    14  	DescribeTable(
    15  		"Unmarshaling",
    16  		func(servicePlan ServicePlan, serialized string) {
    17  			var parsed ServicePlan
    18  			Expect(json.Unmarshal([]byte(serialized), &parsed)).NotTo(HaveOccurred())
    19  			Expect(parsed).To(Equal(servicePlan))
    20  		},
    21  		Entry(
    22  			"basic",
    23  			ServicePlan{
    24  				GUID:                "fake-service-plan-guid",
    25  				Name:                "fake-service-plan-name",
    26  				ServiceOfferingGUID: "fake-service-offering-guid",
    27  			},
    28  			`{
    29  				"guid": "fake-service-plan-guid",
    30  				"name": "fake-service-plan-name",
    31  				"relationships": {
    32  					"service_offering": {
    33  						"data": {
    34  							"guid": "fake-service-offering-guid"
    35  						}
    36  					}
    37  				}
    38  			}`,
    39  		),
    40  		Entry(
    41  			"detailed",
    42  			ServicePlan{
    43  				GUID:                "fake-service-plan-guid",
    44  				Name:                "fake-service-plan-name",
    45  				ServiceOfferingGUID: "fake-service-offering-guid",
    46  				Description:         "fake-description",
    47  				Available:           true,
    48  				VisibilityType:      "public",
    49  				Free:                true,
    50  				Costs: []ServicePlanCost{
    51  					{
    52  						Amount:   12.5,
    53  						Currency: "USD",
    54  						Unit:     "month",
    55  					},
    56  					{
    57  						Amount:   3.25,
    58  						Currency: "EUR",
    59  						Unit:     "day",
    60  					},
    61  				},
    62  				SpaceGUID:                  "fake-space-guid",
    63  				MaintenanceInfoDescription: "cool upgrade",
    64  				MaintenanceInfoVersion:     "1.2.3",
    65  				Metadata: &Metadata{
    66  					Labels: map[string]types.NullString{
    67  						"foo": types.NewNullString("bar"),
    68  						"baz": types.NewNullString(),
    69  					},
    70  				},
    71  			},
    72  			`{
    73  				"guid": "fake-service-plan-guid",
    74  				"name": "fake-service-plan-name",
    75  				"description": "fake-description",
    76  				"available": true,
    77  				"visibility_type": "public",
    78  				"free": true,
    79  				"costs": [
    80  					{
    81  						"amount": 12.5,
    82  						"currency": "USD",
    83  						"unit": "month"
    84  					},
    85  					{
    86  						"amount": 3.25,
    87  						"currency": "EUR",
    88  						"unit": "day"
    89  					}
    90  				],
    91  				"maintenance_info": {
    92  					"description": "cool upgrade",
    93  					"version": "1.2.3"
    94  				},
    95  				"metadata": {
    96  					"labels": {
    97  						"foo": "bar",
    98  						"baz": null
    99  					}
   100  				},
   101  				"relationships": {
   102  					"service_offering": {
   103  						"data": {
   104  							"guid": "fake-service-offering-guid"
   105  						}
   106  					},
   107  					"space": {
   108  						"data": {
   109  							"guid": "fake-space-guid"
   110  						}
   111  					}
   112  				}
   113  			}`,
   114  		),
   115  	)
   116  })