-
Notifications
You must be signed in to change notification settings - Fork 929
/
stack.go
73 lines (57 loc) · 1.54 KB
/
stack.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
package helpers
import (
"encoding/json"
"fmt"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gbytes"
. "github.com/onsi/gomega/gexec"
"strings"
)
type ccStacks struct {
Resources []struct {
Entity struct {
Name string `json:"name"`
} `json:"entity"`
} `json:"resources"`
}
func FetchStacks() []string {
session := CF("curl", "/v2/stacks")
Eventually(session).Should(Exit(0))
var rawStacks ccStacks
err := json.Unmarshal(session.Out.Contents(), &rawStacks)
Expect(err).ToNot(HaveOccurred())
var stacks []string
for _, stack := range rawStacks.Resources {
stacks = append(stacks, stack.Entity.Name)
}
return stacks
}
func CreateStack(names ...string) string {
name := NewStackName()
if len(names) > 0 {
name = names[0]
}
requestBody := fmt.Sprintf(
`{"name":"%s","description":"CF CLI integration test stack, please delete"}`,
name,
)
session := CF("curl", "-v", "-X", "POST", "/v2/stacks", "-d", requestBody)
Eventually(session).Should(Say("201 Created"))
Eventually(session).Should(Exit(0))
return name
}
func DeleteStack(name string) {
session := CF("stack", "--guid", name)
Eventually(session).Should(Exit(0))
guid := strings.TrimSpace(string(session.Out.Contents()))
session = CF("curl", "-v", "-X", "DELETE", "/v2/stacks/"+guid)
Eventually(session).Should(Say("204 No Content"))
Eventually(session).Should(Exit(0))
}
func EnsureMinimumNumberOfStacks(num int) []string {
var stacks []string
for stacks = FetchStacks(); len(stacks) < 2; {
stacks = append(stacks, CreateStack())
}
return stacks
}