forked from cloudfoundry/go-cfclient
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapps_test.go
More file actions
146 lines (124 loc) · 3.86 KB
/
Copy pathapps_test.go
File metadata and controls
146 lines (124 loc) · 3.86 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package cfclient
import (
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestListApps(t *testing.T) {
Convey("List Apps", t, func() {
mocks := []MockRoute{
{"GET", "/v2/apps", listAppsPayload},
{"GET", "/v2/appsPage2", listAppsPayloadPage2},
}
setupMultiple(mocks)
defer teardown()
c := &Config{
ApiAddress: server.URL,
Token: "foobar",
}
client, err := NewClient(c)
So(err, ShouldBeNil)
apps, err := client.ListApps()
So(err, ShouldBeNil)
So(len(apps), ShouldEqual, 2)
So(apps[0].Guid, ShouldEqual, "af15c29a-6bde-4a9b-8cdf-43aa0d4b7e3c")
So(apps[0].Name, ShouldEqual, "app-test")
So(apps[0].Environment["FOOBAR"], ShouldEqual, "QUX")
So(apps[1].Guid, ShouldEqual, "f9ad202b-76dd-44ec-b7c2-fd2417a561e8")
So(apps[1].Name, ShouldEqual, "app-test2")
})
}
func TestAppByGuid(t *testing.T) {
Convey("App By GUID", t, func() {
setup(MockRoute{"GET", "/v2/apps/9902530c-c634-4864-a189-71d763cb12e2", appPayload})
defer teardown()
c := &Config{
ApiAddress: server.URL,
Token: "foobar",
}
client, err := NewClient(c)
So(err, ShouldBeNil)
app, err := client.AppByGuid("9902530c-c634-4864-a189-71d763cb12e2")
So(err, ShouldBeNil)
So(app.Guid, ShouldEqual, "9902530c-c634-4864-a189-71d763cb12e2")
So(app.Name, ShouldEqual, "test-env")
})
Convey("App By GUID with environment variables with different types", t, func() {
setup(MockRoute{"GET", "/v2/apps/9902530c-c634-4864-a189-71d763cb12e2", appPayloadWithEnvironment_json})
defer teardown()
c := &Config{
ApiAddress: server.URL,
Token: "foobar",
}
client, err := NewClient(c)
So(err, ShouldBeNil)
app, err := client.AppByGuid("9902530c-c634-4864-a189-71d763cb12e2")
So(err, ShouldBeNil)
So(app.Environment["string"], ShouldEqual, "string")
So(app.Environment["int"], ShouldEqual, 1)
})
}
func TestGetAppInstances(t *testing.T) {
Convey("App completely running", t, func() {
setup(MockRoute{"GET", "/v2/apps/9902530c-c634-4864-a189-71d763cb12e2/instances", appInstancePayload})
defer teardown()
c := &Config{
ApiAddress: server.URL,
Token: "foobar",
}
client, err := NewClient(c)
So(err, ShouldBeNil)
appInstances, err := client.GetAppInstances("9902530c-c634-4864-a189-71d763cb12e2")
So(err, ShouldBeNil)
So(appInstances["0"].State, ShouldEqual, "RUNNING")
So(appInstances["1"].State, ShouldEqual, "RUNNING")
})
Convey("App partially running", t, func() {
setup(MockRoute{"GET", "/v2/apps/9902530c-c634-4864-a189-71d763cb12e2/instances", appInstanceUnhealthyPayload})
defer teardown()
c := &Config{
ApiAddress: server.URL,
Token: "foobar",
}
client, err := NewClient(c)
So(err, ShouldBeNil)
appInstances, err := client.GetAppInstances("9902530c-c634-4864-a189-71d763cb12e2")
So(err, ShouldBeNil)
So(appInstances["0"].State, ShouldEqual, "RUNNING")
So(appInstances["1"].State, ShouldEqual, "STARTING")
})
}
func TestKillAppInstance(t *testing.T) {
Convey("Kills an app instance", t, func() {
setup(MockRoute{"DELETE", "/v2/apps/9902530c-c634-4864-a189-71d763cb12e2/instances/0", ""})
defer teardown()
c := &Config{
ApiAddress: server.URL,
Token: "foobar",
}
client, err := NewClient(c)
So(err, ShouldBeNil)
So(client.KillAppInstance("9902530c-c634-4864-a189-71d763cb12e2", "0"), ShouldBeNil)
})
}
func TestAppSpace(t *testing.T) {
Convey("Find app space", t, func() {
setup(MockRoute{"GET", "/v2/spaces/foobar", spacePayload})
defer teardown()
c := &Config{
ApiAddress: server.URL,
Token: "foobar",
}
client, err := NewClient(c)
So(err, ShouldBeNil)
app := &App{
Guid: "123",
Name: "test app",
SpaceURL: "/v2/spaces/foobar",
c: client,
}
space, err := app.Space()
So(err, ShouldBeNil)
So(space.Name, ShouldEqual, "test-space")
So(space.Guid, ShouldEqual, "a72fa1e8-c694-47b3-85f2-55f61fd00d73")
})
}