github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/integration/helpers/service_instance.go (about) 1 package helpers 2 3 import ( 4 "encoding/json" 5 "fmt" 6 "strings" 7 8 . "github.com/onsi/gomega" 9 . "github.com/onsi/gomega/gexec" 10 ) 11 12 type ServiceInstanceGUID struct { 13 Resources []struct { 14 Metadata struct { 15 GUID string `json:"guid"` 16 } `json:"metadata"` 17 } `json:"resources"` 18 } 19 20 // ManagedServiceInstanceGUID returns the GUID for a managed service instance. 21 func ManagedServiceInstanceGUID(managedServiceInstanceName string) string { 22 session := CF("curl", fmt.Sprintf("/v2/service_instances?q=name:%s", managedServiceInstanceName)) 23 Eventually(session).Should(Exit(0)) 24 25 rawJSON := strings.TrimSpace(string(session.Out.Contents())) 26 27 var serviceInstanceGUID ServiceInstanceGUID 28 err := json.Unmarshal([]byte(rawJSON), &serviceInstanceGUID) 29 Expect(err).NotTo(HaveOccurred()) 30 31 Expect(serviceInstanceGUID.Resources).To(HaveLen(1)) 32 return serviceInstanceGUID.Resources[0].Metadata.GUID 33 } 34 35 // UserProvidedServiceInstanceGUID returns the GUID for a user provided service instance. 36 func UserProvidedServiceInstanceGUID(userProvidedServiceInstanceName string) string { 37 session := CF("curl", fmt.Sprintf("/v2/user_provided_service_instances?q=name:%s", userProvidedServiceInstanceName)) 38 Eventually(session).Should(Exit(0)) 39 40 rawJSON := strings.TrimSpace(string(session.Out.Contents())) 41 42 var serviceInstanceGUID ServiceInstanceGUID 43 err := json.Unmarshal([]byte(rawJSON), &serviceInstanceGUID) 44 Expect(err).NotTo(HaveOccurred()) 45 46 Expect(serviceInstanceGUID.Resources).To(HaveLen(1)) 47 return serviceInstanceGUID.Resources[0].Metadata.GUID 48 }