forked from cloudfoundry/route-registrar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fake_router_client.go
51 lines (41 loc) · 1.08 KB
/
fake_router_client.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
package fake_gibson
type URIPortRoutePair struct {
port int
uri string
}
type FakeRouterClient struct {
DidGreet bool
RegisteredRoutes []URIPortRoutePair
}
func NewFakeRouterClient() *FakeRouterClient {
return &FakeRouterClient{}
}
func (r *FakeRouterClient) Greet() error {
r.DidGreet = true
return nil
}
func (r *FakeRouterClient) Register(port int, uri string) error {
r.RegisteredRoutes = append(r.RegisteredRoutes, URIPortRoutePair{port, uri})
return nil
}
func (r *FakeRouterClient) Unregister(port int, uri string) error {
for index, uriPortPair := range r.RegisteredRoutes {
if uriPortPair.port == port && uriPortPair.uri == uri {
r.RegisteredRoutes = append(r.RegisteredRoutes[:index], r.RegisteredRoutes[index+1:]...)
break
}
}
return nil
}
func (r *FakeRouterClient) IsRegistered(port int, uri string) bool {
for _, uriPortPair := range r.RegisteredRoutes {
if uriPortPair.port == port && uriPortPair.uri == uri {
return true
}
}
return false
}
func (r *FakeRouterClient) Reset() {
r.DidGreet = false
r.RegisteredRoutes = []URIPortRoutePair{}
}