github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/integration/helpers/isolation_segment.go (about) 1 package helpers 2 3 import ( 4 "encoding/json" 5 "fmt" 6 7 . "github.com/onsi/ginkgo" 8 . "github.com/onsi/gomega" 9 ) 10 11 // GetIsolationSegmentGUID gets the Isolation Segment GUID by passing along the given isolation 12 // segment name as a query parameter in the /v3/isolation_segments?names=name endpoint. 13 func GetIsolationSegmentGUID(name string) string { 14 session := CF("curl", fmt.Sprintf("/v3/isolation_segments?names=%s", name)) 15 bytes := session.Wait("15s").Out.Contents() 16 return getGUID(bytes) 17 } 18 19 func getGUID(response []byte) string { 20 type resource struct { 21 Guid string `json:"guid"` 22 } 23 var GetResponse struct { 24 Resources []resource `json:"resources"` 25 } 26 27 err := json.Unmarshal(response, &GetResponse) 28 Expect(err).ToNot(HaveOccurred()) 29 30 if len(GetResponse.Resources) == 0 { 31 Fail("No guid found for response") 32 } 33 34 return GetResponse.Resources[0].Guid 35 }