github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/cf/api/resources/service_keys_test.go (about) 1 package resources_test 2 3 import ( 4 "encoding/json" 5 6 . "code.cloudfoundry.org/cli/cf/api/resources" 7 8 . "github.com/onsi/ginkgo" 9 . "github.com/onsi/gomega" 10 ) 11 12 var _ = Describe("ServiceKeyResource", func() { 13 var resource ServiceKeyResource 14 15 BeforeEach(func() { 16 err := json.Unmarshal([]byte(` 17 { 18 "metadata": { 19 "guid": "fake-service-key-guid", 20 "url": "/v2/service_keys/fake-guid", 21 "created_at": "2015-01-13T18:52:08+00:00", 22 "updated_at": null 23 }, 24 "entity": { 25 "name": "fake-service-key-name", 26 "service_instance_guid":"fake-service-instance-guid", 27 "service_instance_url":"http://fake/service/instance/url", 28 "credentials": { 29 "username": "fake-username", 30 "password": "fake-password", 31 "host": "fake-host", 32 "port": 3306, 33 "database": "fake-db-name", 34 "uri": "mysql://fake-user:fake-password@fake-host:3306/fake-db-name" 35 } 36 } 37 }`), &resource) 38 39 Expect(err).ToNot(HaveOccurred()) 40 }) 41 42 Context("Brokers unmarshall service keys", func() { 43 Describe("#ToFields", func() { 44 It("unmarshalls the fields of a service key resource", func() { 45 fields := resource.ToFields() 46 47 Expect(fields.GUID).To(Equal("fake-service-key-guid")) 48 Expect(fields.Name).To(Equal("fake-service-key-name")) 49 }) 50 }) 51 52 Describe("#ToModel", func() { 53 It("unmarshalls the service instance resource model", func() { 54 instance := resource.ToModel() 55 56 Expect(instance.Fields.Name).To(Equal("fake-service-key-name")) 57 Expect(instance.Fields.GUID).To(Equal("fake-service-key-guid")) 58 Expect(instance.Fields.URL).To(Equal("/v2/service_keys/fake-guid")) 59 Expect(instance.Fields.ServiceInstanceGUID).To(Equal("fake-service-instance-guid")) 60 Expect(instance.Fields.ServiceInstanceURL).To(Equal("http://fake/service/instance/url")) 61 62 Expect(instance.Credentials).To(HaveKeyWithValue("username", "fake-username")) 63 Expect(instance.Credentials).To(HaveKeyWithValue("password", "fake-password")) 64 Expect(instance.Credentials).To(HaveKeyWithValue("host", "fake-host")) 65 Expect(instance.Credentials).To(HaveKeyWithValue("port", float64(3306))) 66 Expect(instance.Credentials).To(HaveKeyWithValue("database", "fake-db-name")) 67 Expect(instance.Credentials).To(HaveKeyWithValue("uri", "mysql://fake-user:fake-password@fake-host:3306/fake-db-name")) 68 }) 69 }) 70 }) 71 })