-
Notifications
You must be signed in to change notification settings - Fork 929
/
route.go
93 lines (76 loc) · 2.3 KB
/
route.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package helpers
import (
"fmt"
"path"
"regexp"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gbytes"
. "github.com/onsi/gomega/gexec"
)
// MinTestPort should be defined by the CF router group for integration tests.
const MinTestPort = 1024
// MaxTestPort should be defined by the CF router group for integration tests.
const MaxTestPort = 1034
func FindOrCreateTCPRouterGroup(node int) string {
routerGroupName := fmt.Sprintf("INTEGRATION-TCP-NODE-%d", node)
session := CF("curl", fmt.Sprintf("/routing/v1/router_groups?name=%s", routerGroupName))
Eventually(session).Should(Exit(0))
doesNotExist := regexp.MustCompile("ResourceNotFoundError")
if doesNotExist.Match(session.Out.Contents()) {
jsonBody := fmt.Sprintf(`{"name": "%s", "type": "tcp", "reservable_ports": "%d-%d"}`, routerGroupName, MinTestPort, MaxTestPort)
session := CF("curl", "-d", jsonBody, "-X", "POST", "/routing/v1/router_groups")
Eventually(session).Should(Say(`"name":\s*"%s"`, routerGroupName))
Eventually(session).Should(Say(`"type":\s*"tcp"`))
Eventually(session).Should(Exit(0))
}
return routerGroupName
}
type Route struct {
Domain string
Host string
Path string
Port int
Space string
}
func NewRoute(space string, domain string, hostname string, path string) Route {
return Route{
Space: space,
Domain: domain,
Host: hostname,
Path: path,
}
}
func NewTCPRoute(space string, domain string, port int) Route {
return Route{
Space: space,
Domain: domain,
Port: port,
}
}
func (r Route) Create() {
if r.Port != 0 {
Eventually(CF("create-route", r.Space, r.Domain, "--port", fmt.Sprint(r.Port))).Should(Exit(0))
} else {
Eventually(CF("create-route", r.Space, r.Domain, "--hostname", r.Host, "--path", r.Path)).Should(Exit(0))
}
}
func (r Route) Delete() {
if r.Port != 0 {
Eventually(CF("delete-route", r.Domain, "--port", fmt.Sprint(r.Port))).Should(Exit(0))
} else {
Eventually(CF("delete-route", r.Domain, "--hostname", r.Host, "--path", r.Path, "-f")).Should(Exit(0))
}
}
func (r Route) String() string {
routeString := r.Domain
if r.Port != 0 {
routeString = fmt.Sprintf("%s:%d", routeString, r.Port)
}
if r.Host != "" {
routeString = fmt.Sprintf("%s.%s", r.Host, routeString)
}
if r.Path != "" {
routeString = path.Join(routeString, r.Path)
}
return routeString
}