github.com/loafoe/cli@v7.1.0+incompatible/integration/helpers/router_group.go (about)

     1  package helpers
     2  
     3  import (
     4  	"fmt"
     5  	"regexp"
     6  
     7  	. "github.com/onsi/gomega"
     8  	. "github.com/onsi/gomega/gexec"
     9  )
    10  
    11  type RouterGroup struct {
    12  	Name            string
    13  	ReservablePorts string
    14  	guid            string
    15  }
    16  
    17  func NewRouterGroup(name, reservablePorts string) RouterGroup {
    18  	return RouterGroup{
    19  		Name:            name,
    20  		ReservablePorts: reservablePorts,
    21  	}
    22  }
    23  
    24  func (rg *RouterGroup) Create() {
    25  	session := CF("curl", "-X", "POST", "/routing/v1/router_groups", "-d", fmt.Sprintf(`{
    26  		"name": "%s",
    27  		"type": "tcp",
    28  		"reservable_ports": "%s"
    29  	}`, rg.Name, rg.ReservablePorts))
    30  
    31  	Eventually(session).Should(Exit(0))
    32  
    33  	// Capture the guid from the response so this group can be deleted later
    34  	stdout := string(session.Out.Contents())
    35  	guidFieldRegex := regexp.MustCompile(`"guid":\s*"([^"]+)"`)
    36  	guidMatch := guidFieldRegex.FindStringSubmatch(stdout)
    37  	Expect(guidMatch).NotTo(BeNil())
    38  
    39  	rg.guid = guidMatch[1]
    40  }
    41  
    42  func (rg *RouterGroup) Delete() {
    43  	session := CF("curl", "--fail", "-X", "DELETE", fmt.Sprintf("/routing/v1/router_groups/%s", rg.guid))
    44  
    45  	Eventually(session).Should(Exit(0))
    46  }