forked from cloudfoundry-community/cloudfoundry-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
route.go
113 lines (92 loc) · 2.39 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package helpers
import (
"fmt"
"path"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gbytes"
. "github.com/onsi/gomega/gexec"
)
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
}
func DomainName(prefix ...string) string {
if len(prefix) > 0 {
return fmt.Sprintf("integration-%s.com", PrefixedRandomName(prefix[0]))
}
return fmt.Sprintf("integration%s.com", PrefixedRandomName(""))
}
type Domain struct {
Org string
Name string
}
func NewDomain(org string, name string) Domain {
return Domain{
Org: org,
Name: name,
}
}
func (d Domain) Create() {
Eventually(CF("create-domain", d.Org, d.Name)).Should(Exit(0))
Eventually(CF("domains")).Should(And(Exit(0), Say(d.Name)))
}
func (d Domain) CreateShared() {
Eventually(CF("create-shared-domain", d.Name)).Should(Exit(0))
}
func (d Domain) CreateWithRouterGroup(routerGroup string) {
Eventually(CF("create-shared-domain", d.Name, "--router-group", routerGroup)).Should(Exit(0))
}
func (d Domain) Share() {
Eventually(CF("share-private-domain", d.Org, d.Name)).Should(Exit(0))
}
func (d Domain) Delete() {
Eventually(CF("delete-domain", d.Name, "-f")).Should(Exit(0))
}
func (d Domain) DeleteShared() {
Eventually(CF("delete-shared-domain", d.Name, "-f")).Should(Exit(0))
}