forked from cloudfoundry/cli
/
fake_route_repo.go
109 lines (86 loc) · 2.52 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
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
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) 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) 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
}