github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+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  func GetIsolationSegmentGUID(name string) string {
    12  	session := CF("curl", fmt.Sprintf("/v3/isolation_segments?names=%s", name))
    13  	bytes := session.Wait("15s").Out.Contents()
    14  	return getGUID(bytes)
    15  }
    16  
    17  func getGUID(response []byte) string {
    18  	type resource struct {
    19  		Guid string `json:"guid"`
    20  	}
    21  	var GetResponse struct {
    22  		Resources []resource `json:"resources"`
    23  	}
    24  
    25  	err := json.Unmarshal(response, &GetResponse)
    26  	Expect(err).ToNot(HaveOccurred())
    27  
    28  	if len(GetResponse.Resources) == 0 {
    29  		Fail("No guid found for response")
    30  	}
    31  
    32  	return GetResponse.Resources[0].Guid
    33  }