github.com/rakutentech/cli@v6.12.5-0.20151006231303-24468b65536e+incompatible/cf/api/fakes/fake_route_repo.go (about) 1 package fakes 2 3 import ( 4 "github.com/cloudfoundry/cli/cf/errors" 5 "github.com/cloudfoundry/cli/cf/models" 6 ) 7 8 type FakeRouteRepository struct { 9 FindByHostAndDomainCalledWith struct { 10 Host string 11 Domain models.DomainFields 12 } 13 14 FindByHostAndDomainReturns struct { 15 Route models.Route 16 Error error 17 } 18 19 CreatedHost string 20 CreatedDomainGuid string 21 CreatedRoute models.Route 22 23 CreateInSpaceHost string 24 CreateInSpaceDomainGuid string 25 CreateInSpaceSpaceGuid string 26 CreateInSpaceCreatedRoute models.Route 27 CreateInSpaceErr bool 28 29 CheckIfExistsFound bool 30 CheckIfExistsError error 31 32 BindErr error 33 BoundRouteGuid string 34 BoundAppGuid string 35 36 UnboundRouteGuid string 37 UnboundAppGuid string 38 39 ListErr bool 40 Routes []models.Route 41 42 DeletedRouteGuids []string 43 DeleteErr error 44 } 45 46 func (repo *FakeRouteRepository) ListRoutes(cb func(models.Route) bool) (apiErr error) { 47 if repo.ListErr { 48 return errors.New("WHOOPSIE") 49 } 50 51 for _, route := range repo.Routes { 52 if !cb(route) { 53 break 54 } 55 } 56 return 57 } 58 59 func (repo *FakeRouteRepository) ListAllRoutes(cb func(models.Route) bool) (apiErr error) { 60 if repo.ListErr { 61 return errors.New("WHOOPSIE") 62 } 63 64 for _, route := range repo.Routes { 65 if !cb(route) { 66 break 67 } 68 } 69 return 70 } 71 72 func (repo *FakeRouteRepository) FindByHostAndDomain(host string, domain models.DomainFields) (route models.Route, apiErr error) { 73 repo.FindByHostAndDomainCalledWith.Host = host 74 repo.FindByHostAndDomainCalledWith.Domain = domain 75 76 if repo.FindByHostAndDomainReturns.Error != nil { 77 apiErr = repo.FindByHostAndDomainReturns.Error 78 } 79 80 route = repo.FindByHostAndDomainReturns.Route 81 return 82 } 83 84 func (repo *FakeRouteRepository) Create(host string, domain models.DomainFields) (createdRoute models.Route, apiErr error) { 85 repo.CreatedHost = host 86 repo.CreatedDomainGuid = domain.Guid 87 88 createdRoute.Guid = host + "-route-guid" 89 createdRoute.Domain = domain 90 createdRoute.Host = host 91 92 return 93 } 94 95 func (repo *FakeRouteRepository) CheckIfExists(host string, domain models.DomainFields) (found bool, apiErr error) { 96 if repo.CheckIfExistsFound { 97 found = true 98 } else { 99 found = false 100 } 101 102 if repo.CheckIfExistsError != nil { 103 apiErr = repo.CheckIfExistsError 104 } 105 return 106 } 107 func (repo *FakeRouteRepository) CreateInSpace(host, domainGuid, spaceGuid string) (createdRoute models.Route, apiErr error) { 108 repo.CreateInSpaceHost = host 109 repo.CreateInSpaceDomainGuid = domainGuid 110 repo.CreateInSpaceSpaceGuid = spaceGuid 111 112 if repo.CreateInSpaceErr { 113 apiErr = errors.New("Error") 114 } else { 115 createdRoute = repo.CreateInSpaceCreatedRoute 116 } 117 118 return 119 } 120 121 func (repo *FakeRouteRepository) Bind(routeGuid, appGuid string) (apiErr error) { 122 repo.BoundRouteGuid = routeGuid 123 repo.BoundAppGuid = appGuid 124 return repo.BindErr 125 } 126 127 func (repo *FakeRouteRepository) Unbind(routeGuid, appGuid string) (apiErr error) { 128 repo.UnboundRouteGuid = routeGuid 129 repo.UnboundAppGuid = appGuid 130 return 131 } 132 133 func (repo *FakeRouteRepository) Delete(routeGuid string) (apiErr error) { 134 repo.DeletedRouteGuids = append(repo.DeletedRouteGuids, routeGuid) 135 apiErr = repo.DeleteErr 136 return 137 }