forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfake_org_repo.go
75 lines (60 loc) · 1.57 KB
/
fake_org_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
package fakes
import (
"github.com/cloudfoundry/cli/cf/errors"
"github.com/cloudfoundry/cli/cf/models"
)
type FakeOrgRepository struct {
Organizations []models.Organization
CreateName string
CreateOrgExists bool
FindByNameName string
FindByNameErr bool
FindByNameNotFound bool
FindByNameOrganization models.Organization
RenameOrganizationGuid string
RenameNewName string
DeletedOrganizationGuid string
}
func (repo FakeOrgRepository) ListOrgs(cb func(models.Organization) bool) (apiErr error) {
for _, org := range repo.Organizations {
if !cb(org) {
break
}
}
return
}
func (repo *FakeOrgRepository) FindByName(name string) (org models.Organization, apiErr error) {
repo.FindByNameName = name
var foundOrg bool = false
for _, anOrg := range repo.Organizations {
if name == anOrg.Name {
foundOrg = true
org = anOrg
break
}
}
if repo.FindByNameErr || !foundOrg {
apiErr = errors.New("Error finding organization by name.")
}
if repo.FindByNameNotFound {
apiErr = errors.NewModelNotFoundError("Org", name)
}
return
}
func (repo *FakeOrgRepository) Create(name string) (apiErr error) {
if repo.CreateOrgExists {
apiErr = errors.NewHttpError(400, errors.ORG_EXISTS, "Space already exists")
return
}
repo.CreateName = name
return
}
func (repo *FakeOrgRepository) Rename(orgGuid string, name string) (apiErr error) {
repo.RenameOrganizationGuid = orgGuid
repo.RenameNewName = name
return
}
func (repo *FakeOrgRepository) Delete(orgGuid string) (apiErr error) {
repo.DeletedOrganizationGuid = orgGuid
return
}