github.com/asifdxtreme/cli@v6.1.3-0.20150123051144-9ead8700b4ae+incompatible/cf/api/resources/service_instances_test.go (about)

     1  package resources_test
     2  
     3  import (
     4  	"encoding/json"
     5  
     6  	. "github.com/cloudfoundry/cli/cf/api/resources"
     7  
     8  	. "github.com/onsi/ginkgo"
     9  	. "github.com/onsi/gomega"
    10  )
    11  
    12  var _ = Describe("ServiceInstanceResource", func() {
    13  	var resource ServiceInstanceResource
    14  
    15  	BeforeEach(func() {
    16  		err := json.Unmarshal([]byte(`
    17      {
    18        "metadata": {
    19          "guid": "fake-guid",
    20          "url": "/v2/service_instances/fake-guid",
    21          "created_at": "2015-01-13T18:52:08+00:00",
    22          "updated_at": null
    23        },
    24        "entity": {
    25          "name": "fake service name",
    26          "credentials": {
    27          },
    28          "service_plan_guid": "fake-service-plan-guid",
    29          "space_guid": "fake-space-guid",
    30          "gateway_data": null,
    31          "dashboard_url": "https://fake/dashboard/url",
    32          "type": "managed_service_instance",
    33          "space_url": "/v2/spaces/fake-space-guid",
    34          "service_plan_url": "/v2/service_plans/fake-service-plan-guid",
    35          "service_bindings_url": "/v2/service_instances/fake-guid/service_bindings",
    36          "state": "creating",
    37          "state_description": "fake state description",
    38          "service_plan": {
    39            "metadata": {
    40              "guid": "fake-service-plan-guid"
    41            },
    42            "entity": {
    43              "name": "fake-service-plan-name",
    44              "free": true,
    45              "description": "fake-description",
    46              "public": true,
    47              "active": true,
    48              "service_guid": "fake-service-guid"
    49            }
    50          },
    51          "service_bindings": [{
    52            "metadata": {
    53              "guid": "fake-service-binding-guid",
    54              "url": "http://fake/url"
    55            },
    56            "entity": {
    57              "app_guid": "fake-app-guid"
    58            }
    59          }]
    60        }
    61      }`), &resource)
    62  
    63  		Expect(err).ToNot(HaveOccurred())
    64  	})
    65  
    66  	Describe("#ToFields", func() {
    67  		It("unmarshalls the fields of a service instance resource", func() {
    68  			fields := resource.ToFields()
    69  
    70  			Expect(fields.Guid).To(Equal("fake-guid"))
    71  			Expect(fields.Name).To(Equal("fake service name"))
    72  			Expect(fields.DashboardUrl).To(Equal("https://fake/dashboard/url"))
    73  			Expect(fields.State).To(Equal("creating"))
    74  			Expect(fields.StateDescription).To(Equal("fake state description"))
    75  		})
    76  	})
    77  
    78  	Describe("#ToModel", func() {
    79  		It("unmarshalls the service instance resource model", func() {
    80  			instance := resource.ToModel()
    81  
    82  			Expect(instance.ServiceInstanceFields.Guid).To(Equal("fake-guid"))
    83  			Expect(instance.ServiceInstanceFields.Name).To(Equal("fake service name"))
    84  			Expect(instance.ServiceInstanceFields.DashboardUrl).To(Equal("https://fake/dashboard/url"))
    85  			Expect(instance.ServiceInstanceFields.State).To(Equal("creating"))
    86  			Expect(instance.ServiceInstanceFields.StateDescription).To(Equal("fake state description"))
    87  
    88  			Expect(instance.ServicePlan.Guid).To(Equal("fake-service-plan-guid"))
    89  			Expect(instance.ServicePlan.Free).To(BeTrue())
    90  			Expect(instance.ServicePlan.Description).To(Equal("fake-description"))
    91  			Expect(instance.ServicePlan.Public).To(BeTrue())
    92  			Expect(instance.ServicePlan.Active).To(BeTrue())
    93  			Expect(instance.ServicePlan.ServiceOfferingGuid).To(Equal("fake-service-guid"))
    94  
    95  			Expect(instance.ServiceBindings[0].Guid).To(Equal("fake-service-binding-guid"))
    96  			Expect(instance.ServiceBindings[0].Url).To(Equal("http://fake/url"))
    97  			Expect(instance.ServiceBindings[0].AppGuid).To(Equal("fake-app-guid"))
    98  		})
    99  	})
   100  })