forked from cloudfoundry/go-cfclient
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroutes_test.go
94 lines (80 loc) · 2.6 KB
/
routes_test.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
package cfclient
import (
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestListRoutes(t *testing.T) {
Convey("List Routes", t, func() {
mocks := []MockRoute{
{"GET", "/v2/routes", listRoutesPayloadPage1, "", 200, "", nil},
{"GET", "/v2/routes_page_2", listRoutesPayloadPage2, "", 200, "", nil},
}
setupMultiple(mocks, t)
defer teardown()
c := &Config{
ApiAddress: server.URL,
Token: "foobar",
}
client, err := NewClient(c)
So(err, ShouldBeNil)
routes, err := client.ListRoutes()
So(err, ShouldBeNil)
So(len(routes), ShouldEqual, 2)
So(routes[0].Guid, ShouldEqual, "24707add-83b8-4fd8-a8f4-b7297199c805")
So(routes[0].Host, ShouldEqual, "test-1")
So(routes[0].Path, ShouldEqual, "/foo")
So(routes[0].DomainGuid, ShouldEqual, "0b183484-45cc-4855-94d4-892f80f20c13")
So(routes[0].SpaceGuid, ShouldEqual, "494d8b64-8181-4183-a6d3-6279db8fec6e")
So(routes[0].ServiceInstanceGuid, ShouldEqual, "")
So(routes[0].Port, ShouldEqual, 0)
})
}
func TestCreateTcpRoute(t *testing.T) {
Convey("Create TCP Route", t, func() {
setup(MockRoute{"POST", "/v2/routes", createRoute, "", 201, "generate_port=true", nil}, t)
defer teardown()
c := &Config{
ApiAddress: server.URL,
Token: "foobar",
}
client, err := NewClient(c)
So(err, ShouldBeNil)
routeRequest := RouteRequest{
DomainGuid: "08167353-32da-4ed9-9ef5-aa7b31bbc009",
SpaceGuid: "b65a9a76-8c55-460b-9162-18b396da66cf",
}
route, err := client.CreateTcpRoute(routeRequest)
So(err, ShouldBeNil)
So(route.SpaceGuid, ShouldEqual, "b65a9a76-8c55-460b-9162-18b396da66cf")
So(route.DomainGuid, ShouldEqual, "08167353-32da-4ed9-9ef5-aa7b31bbc009")
So(route.Port, ShouldEqual, 1099)
})
}
func TestDeleteRoute(t *testing.T) {
Convey("Delete route", t, func() {
Convey("When a successful status code is returned", func() {
setup(MockRoute{"DELETE", "/v2/routes/a537761f-9d93-4b30-af17-3d73dbca181b", "", "", 204, "", nil}, t)
defer teardown()
c := &Config{
ApiAddress: server.URL,
Token: "foobar",
}
client, err := NewClient(c)
So(err, ShouldBeNil)
err = client.DeleteRoute("a537761f-9d93-4b30-af17-3d73dbca181b")
So(err, ShouldBeNil)
})
Convey("When an error status code is returned", func() {
setup(MockRoute{"DELETE", "/v2/routes/a537761f-9d93-4b30-af17-3d73dbca181b", "", "", 404, "", nil}, t)
defer teardown()
c := &Config{
ApiAddress: server.URL,
Token: "foobar",
}
client, err := NewClient(c)
So(err, ShouldBeNil)
err = client.DeleteRoute("a537761f-9d93-4b30-af17-3d73dbca181b")
So(err, ShouldNotBeNil)
})
})
}