forked from cloudfoundry/go-cfclient
-
Notifications
You must be signed in to change notification settings - Fork 0
/
domains_test.go
176 lines (153 loc) · 5.29 KB
/
domains_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
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
package cfclient
import (
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestListDomains(t *testing.T) {
Convey("List domains", t, func() {
setup(MockRoute{"GET", "/v2/private_domains", listDomainsPayload, "", 200, "", nil}, t)
defer teardown()
c := &Config{
ApiAddress: server.URL,
Token: "foobar",
}
client, err := NewClient(c)
So(err, ShouldBeNil)
domains, err := client.ListDomains()
So(err, ShouldBeNil)
So(len(domains), ShouldEqual, 4)
So(domains[0].Guid, ShouldEqual, "b2a35f0c-d5ad-4a59-bea7-461711d96b0d")
So(domains[0].Name, ShouldEqual, "vcap.me")
So(domains[0].OwningOrganizationGuid, ShouldEqual, "4cf3bc47-eccd-4662-9322-7833c3bdcded")
So(domains[0].OwningOrganizationUrl, ShouldEqual, "/v2/organizations/4cf3bc47-eccd-4662-9322-7833c3bdcded")
So(domains[0].SharedOrganizationsUrl, ShouldEqual, "/v2/private_domains/b2a35f0c-d5ad-4a59-bea7-461711d96b0d/shared_organizations")
})
}
func TestListSharedDomains(t *testing.T) {
Convey("List shared domains", t, func() {
setup(MockRoute{"GET", "/v2/shared_domains", listSharedDomainsPayload, "", 200, "", nil}, t)
defer teardown()
c := &Config{
ApiAddress: server.URL,
Token: "foobar",
}
client, err := NewClient(c)
So(err, ShouldBeNil)
domains, err := client.ListSharedDomains()
So(err, ShouldBeNil)
So(len(domains), ShouldEqual, 1)
So(domains[0].Guid, ShouldEqual, "91977695-8ad9-40db-858f-4df782603ec3")
So(domains[0].Name, ShouldEqual, "domain-49.example.com")
So(domains[0].RouterGroupGuid, ShouldEqual, "my-random-guid")
So(domains[0].RouterGroupType, ShouldEqual, "tcp")
})
}
func TestGetDomainByName(t *testing.T) {
Convey("Get domain by name", t, func() {
setup(MockRoute{"GET", "/v2/private_domains", listDomainsPayload, "", 200, "q=name:vcap.me", nil}, t)
defer teardown()
c := &Config{
ApiAddress: server.URL,
Token: "foobar",
}
client, err := NewClient(c)
So(err, ShouldBeNil)
domain, err := client.GetDomainByName("vcap.me")
So(err, ShouldBeNil)
So(domain.Guid, ShouldEqual, "b2a35f0c-d5ad-4a59-bea7-461711d96b0d")
So(domain.Name, ShouldEqual, "vcap.me")
})
Convey("Get domain by name with an endpoint that returns a 404", t, func() {
setup(MockRoute{"GET", "/v2/private_domains", listDomainsEmptyResponse, "", 404, "q=name:vcap.me", nil}, t)
defer teardown()
c := &Config{
ApiAddress: server.URL,
Token: "foobar",
}
client, err := NewClient(c)
So(err, ShouldBeNil)
_, listErr := client.GetDomainByName("vcap.me")
So(listErr, ShouldNotBeNil)
})
Convey("Get domain by name for a non-existing domain", t, func() {
setup(MockRoute{"GET", "/v2/private_domains", listDomainsEmptyResponse, "", 200, "q=name:idontexist", nil}, t)
defer teardown()
c := &Config{
ApiAddress: server.URL,
Token: "foobar",
}
client, err := NewClient(c)
So(err, ShouldBeNil)
_, listErr := client.GetDomainByName("idontexist")
So(listErr, ShouldNotBeNil)
})
}
func TestGetSharedDomainByName(t *testing.T) {
Convey("Get shared domain by name", t, func() {
setup(MockRoute{"GET", "/v2/shared_domains", listSharedDomainsPayload, "", 200, "q=name:domain-49.example.com", nil}, t)
defer teardown()
c := &Config{
ApiAddress: server.URL,
Token: "foobar",
}
client, err := NewClient(c)
So(err, ShouldBeNil)
domain, err := client.GetSharedDomainByName("domain-49.example.com")
So(err, ShouldBeNil)
So(domain.Guid, ShouldEqual, "91977695-8ad9-40db-858f-4df782603ec3")
So(domain.Name, ShouldEqual, "domain-49.example.com")
})
Convey("Get shared domain by name with an endpoint that returns a 404", t, func() {
setup(MockRoute{"GET", "/v2/shared_domains", listDomainsEmptyResponse, "", 404, "q=name:domain-49.example.com", nil}, t)
defer teardown()
c := &Config{
ApiAddress: server.URL,
Token: "foobar",
}
client, err := NewClient(c)
So(err, ShouldBeNil)
_, listErr := client.GetSharedDomainByName("domain-49.example.com")
So(listErr, ShouldNotBeNil)
})
Convey("Get shared domain by name for a non-existing domain", t, func() {
setup(MockRoute{"GET", "/v2/shared_domains", listDomainsEmptyResponse, "", 200, "q=name:idontexist", nil}, t)
defer teardown()
c := &Config{
ApiAddress: server.URL,
Token: "foobar",
}
client, err := NewClient(c)
So(err, ShouldBeNil)
_, listErr := client.GetSharedDomainByName("idontexist")
So(listErr, ShouldNotBeNil)
})
}
func TestCreateDomain(t *testing.T) {
Convey("Create domain", t, func() {
setup(MockRoute{"POST", "/v2/private_domains", postDomainPayload, "", 201, "", nil}, t)
defer teardown()
c := &Config{
ApiAddress: server.URL,
Token: "foobar",
}
client, err := NewClient(c)
So(err, ShouldBeNil)
domain, err := client.CreateDomain("exmaple.com", "8483e4f1-d3a3-43e2-ab8c-b05ea40ef8db")
So(err, ShouldBeNil)
So(domain.Guid, ShouldEqual, "b98aeca1-22b9-49f9-8428-3ace9ea2ba11")
})
}
func TestDeleteDomain(t *testing.T) {
Convey("Delete domain", t, func() {
setup(MockRoute{"DELETE", "/v2/private_domains/b2a35f0c-d5ad-4a59-bea7-461711d96b0d", "", "", 204, "", nil}, t)
defer teardown()
c := &Config{
ApiAddress: server.URL,
Token: "foobar",
}
client, err := NewClient(c)
So(err, ShouldBeNil)
err = client.DeleteDomain("b2a35f0c-d5ad-4a59-bea7-461711d96b0d")
So(err, ShouldBeNil)
})
}