github.com/asifdxtreme/cli@v6.1.3-0.20150123051144-9ead8700b4ae+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) FindByHostAndDomain(host string, domain models.DomainFields) (route models.Route, apiErr error) { 60 repo.FindByHostAndDomainCalledWith.Host = host 61 repo.FindByHostAndDomainCalledWith.Domain = domain 62 63 if repo.FindByHostAndDomainReturns.Error != nil { 64 apiErr = repo.FindByHostAndDomainReturns.Error 65 } 66 67 route = repo.FindByHostAndDomainReturns.Route 68 return 69 } 70 71 func (repo *FakeRouteRepository) Create(host string, domain models.DomainFields) (createdRoute models.Route, apiErr error) { 72 repo.CreatedHost = host 73 repo.CreatedDomainGuid = domain.Guid 74 75 createdRoute.Guid = host + "-route-guid" 76 createdRoute.Domain = domain 77 createdRoute.Host = host 78 79 return 80 } 81 82 func (repo *FakeRouteRepository) CheckIfExists(host string, domain models.DomainFields) (found bool, apiErr error) { 83 if repo.CheckIfExistsFound { 84 found = true 85 } else { 86 found = false 87 } 88 89 if repo.CheckIfExistsError != nil { 90 apiErr = repo.CheckIfExistsError 91 } 92 return 93 } 94 func (repo *FakeRouteRepository) CreateInSpace(host, domainGuid, spaceGuid string) (createdRoute models.Route, apiErr error) { 95 repo.CreateInSpaceHost = host 96 repo.CreateInSpaceDomainGuid = domainGuid 97 repo.CreateInSpaceSpaceGuid = spaceGuid 98 99 if repo.CreateInSpaceErr { 100 apiErr = errors.New("Error") 101 } else { 102 createdRoute = repo.CreateInSpaceCreatedRoute 103 } 104 105 return 106 } 107 108 func (repo *FakeRouteRepository) Bind(routeGuid, appGuid string) (apiErr error) { 109 repo.BoundRouteGuid = routeGuid 110 repo.BoundAppGuid = appGuid 111 return repo.BindErr 112 } 113 114 func (repo *FakeRouteRepository) Unbind(routeGuid, appGuid string) (apiErr error) { 115 repo.UnboundRouteGuid = routeGuid 116 repo.UnboundAppGuid = appGuid 117 return 118 } 119 120 func (repo *FakeRouteRepository) Delete(routeGuid string) (apiErr error) { 121 repo.DeletedRouteGuids = append(repo.DeletedRouteGuids, routeGuid) 122 apiErr = repo.DeleteErr 123 return 124 }