github.com/DaAlbrecht/cf-cli@v0.0.0-20231128151943-1fe19bb400b9/resources/service_instance_usage_summary_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 usage resource", func() {
    13  	DescribeTable(
    14  		"Unmarshaling",
    15  		func(serviceInstanceUsageSummaryList ServiceInstanceUsageSummaryList, serialized string) {
    16  			var parsed ServiceInstanceUsageSummaryList
    17  			Expect(json.Unmarshal([]byte(serialized), &parsed)).NotTo(HaveOccurred())
    18  			Expect(parsed).To(Equal(serviceInstanceUsageSummaryList))
    19  		},
    20  		Entry("space_guid", ServiceInstanceUsageSummaryList{UsageSummary: []ServiceInstanceUsageSummary{{SpaceGUID: "fake-space-guid"}}}, `{"usage_summary":[{"space": {"guid": "fake-space-guid"}}]}`),
    21  		Entry("bound_app_count", ServiceInstanceUsageSummaryList{UsageSummary: []ServiceInstanceUsageSummary{{BoundAppCount: 2}}}, `{"usage_summary":[{"bound_app_count": 2}]}`),
    22  		Entry(
    23  			"everything",
    24  			ServiceInstanceUsageSummaryList{
    25  				UsageSummary: []ServiceInstanceUsageSummary{
    26  					{
    27  						SpaceGUID:     "fake-space-guid",
    28  						BoundAppCount: 4,
    29  					},
    30  					{
    31  						SpaceGUID:     "other-fake-space-guid",
    32  						BoundAppCount: 3,
    33  					},
    34  				},
    35  			},
    36  			`{
    37  				"usage_summary": [
    38  					{
    39  					   "space": {
    40  							"guid": "fake-space-guid"
    41  						},
    42  						"bound_app_count": 4
    43  					},
    44  				   {
    45  						"space": {
    46  							"guid": "other-fake-space-guid"
    47  						},
    48  						"bound_app_count": 3
    49  					}
    50  				]
    51  			}`,
    52  		),
    53  	)
    54  })