forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fake_route_repo.go
137 lines (110 loc) · 3.07 KB
/
fake_route_repo.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
package fakes
import (
"github.com/cloudfoundry/cli/cf/errors"
"github.com/cloudfoundry/cli/cf/models"
)
type FakeRouteRepository struct {
FindByHostAndDomainCalledWith struct {
Host string
Domain models.DomainFields
}
FindByHostAndDomainReturns struct {
Route models.Route
Error error
}
CreatedHost string
CreatedDomainGuid string
CreatedRoute models.Route
CreateInSpaceHost string
CreateInSpaceDomainGuid string
CreateInSpaceSpaceGuid string
CreateInSpaceCreatedRoute models.Route
CreateInSpaceErr bool
CheckIfExistsFound bool
CheckIfExistsError error
BindErr error
BoundRouteGuid string
BoundAppGuid string
UnboundRouteGuid string
UnboundAppGuid string
ListErr bool
Routes []models.Route
DeletedRouteGuids []string
DeleteErr error
}
func (repo *FakeRouteRepository) ListRoutes(cb func(models.Route) bool) (apiErr error) {
if repo.ListErr {
return errors.New("WHOOPSIE")
}
for _, route := range repo.Routes {
if !cb(route) {
break
}
}
return
}
func (repo *FakeRouteRepository) ListAllRoutes(cb func(models.Route) bool) (apiErr error) {
if repo.ListErr {
return errors.New("WHOOPSIE")
}
for _, route := range repo.Routes {
if !cb(route) {
break
}
}
return
}
func (repo *FakeRouteRepository) FindByHostAndDomain(host string, domain models.DomainFields) (route models.Route, apiErr error) {
repo.FindByHostAndDomainCalledWith.Host = host
repo.FindByHostAndDomainCalledWith.Domain = domain
if repo.FindByHostAndDomainReturns.Error != nil {
apiErr = repo.FindByHostAndDomainReturns.Error
}
route = repo.FindByHostAndDomainReturns.Route
return
}
func (repo *FakeRouteRepository) Create(host string, domain models.DomainFields) (createdRoute models.Route, apiErr error) {
repo.CreatedHost = host
repo.CreatedDomainGuid = domain.Guid
createdRoute.Guid = host + "-route-guid"
createdRoute.Domain = domain
createdRoute.Host = host
return
}
func (repo *FakeRouteRepository) CheckIfExists(host string, domain models.DomainFields) (found bool, apiErr error) {
if repo.CheckIfExistsFound {
found = true
} else {
found = false
}
if repo.CheckIfExistsError != nil {
apiErr = repo.CheckIfExistsError
}
return
}
func (repo *FakeRouteRepository) CreateInSpace(host, domainGuid, spaceGuid string) (createdRoute models.Route, apiErr error) {
repo.CreateInSpaceHost = host
repo.CreateInSpaceDomainGuid = domainGuid
repo.CreateInSpaceSpaceGuid = spaceGuid
if repo.CreateInSpaceErr {
apiErr = errors.New("Error")
} else {
createdRoute = repo.CreateInSpaceCreatedRoute
}
return
}
func (repo *FakeRouteRepository) Bind(routeGuid, appGuid string) (apiErr error) {
repo.BoundRouteGuid = routeGuid
repo.BoundAppGuid = appGuid
return repo.BindErr
}
func (repo *FakeRouteRepository) Unbind(routeGuid, appGuid string) (apiErr error) {
repo.UnboundRouteGuid = routeGuid
repo.UnboundAppGuid = appGuid
return
}
func (repo *FakeRouteRepository) Delete(routeGuid string) (apiErr error) {
repo.DeletedRouteGuids = append(repo.DeletedRouteGuids, routeGuid)
apiErr = repo.DeleteErr
return
}