github.com/LukasHeimann/cloudfoundrycli/v8@v8.4.4/integration/helpers/service_instance.go (about)

     1  package helpers
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  
     7  	. "github.com/onsi/gomega/gbytes"
     8  
     9  	"code.cloudfoundry.org/jsonry"
    10  	. "github.com/onsi/gomega"
    11  	. "github.com/onsi/gomega/gexec"
    12  )
    13  
    14  func ServiceInstanceGUID(serviceInstanceName string) string {
    15  	session := CF("curl", fmt.Sprintf("/v3/service_instances?names=%s", serviceInstanceName))
    16  	Eventually(session).Should(Exit(0))
    17  
    18  	rawJSON := strings.TrimSpace(string(session.Out.Contents()))
    19  
    20  	var serviceInstanceDetails struct {
    21  		GUIDs []string `jsonry:"resources.guid"`
    22  	}
    23  	err := jsonry.Unmarshal([]byte(rawJSON), &serviceInstanceDetails)
    24  	Expect(err).NotTo(HaveOccurred())
    25  
    26  	Expect(serviceInstanceDetails.GUIDs).NotTo(BeEmpty(), fmt.Sprintf("service instance %s not found", serviceInstanceName))
    27  	Expect(serviceInstanceDetails.GUIDs[0]).To(HaveLen(36), fmt.Sprintf("invalid GUID: '%s'", serviceInstanceDetails.GUIDs[0]))
    28  	return serviceInstanceDetails.GUIDs[0]
    29  }
    30  
    31  // CreateManagedServiceInstance also waits for completion
    32  func CreateManagedServiceInstance(offering, plan, name string, additional ...string) {
    33  	create := []string{"create-service", offering, plan, name}
    34  	session := CF(append(create, additional...)...)
    35  	Eventually(session).Should(Exit(0))
    36  
    37  	Eventually(func() *Buffer {
    38  		return CF("service", name).Wait().Out
    39  	}).Should(Say(`status:\s+create succeeded`))
    40  }