forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fake_space_repo.go
103 lines (82 loc) · 2.23 KB
/
fake_space_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
package api
import (
"cf/errors"
"cf/models"
)
type FakeSpaceRepository struct {
CurrentSpace models.Space
Spaces []models.Space
FindByNameName string
FindByNameSpace models.Space
FindByNameErr bool
FindByNameNotFound bool
FindByNameInOrgName string
FindByNameInOrgOrgGuid string
FindByNameInOrgSpace models.Space
SummarySpace models.Space
CreateSpaceName string
CreateSpaceOrgGuid string
CreateSpaceExists bool
CreateSpaceSpace models.Space
RenameSpaceGuid string
RenameNewName string
DeletedSpaceGuid string
}
func (repo FakeSpaceRepository) GetCurrentSpace() (space models.Space) {
return repo.CurrentSpace
}
func (repo FakeSpaceRepository) ListSpaces(callback func(models.Space) bool) error {
for _, space := range repo.Spaces {
if !callback(space) {
break
}
}
return nil
}
func (repo *FakeSpaceRepository) FindByName(name string) (space models.Space, apiErr error) {
repo.FindByNameName = name
var foundSpace bool = false
for _, someSpace := range repo.Spaces {
if name == someSpace.Name {
foundSpace = true
space = someSpace
break
}
}
if repo.FindByNameErr || !foundSpace {
apiErr = errors.New("Error finding space by name.")
}
if repo.FindByNameNotFound {
apiErr = errors.NewModelNotFoundError("Space", name)
}
return
}
func (repo *FakeSpaceRepository) FindByNameInOrg(name, orgGuid string) (space models.Space, apiErr error) {
repo.FindByNameInOrgName = name
repo.FindByNameInOrgOrgGuid = orgGuid
space = repo.FindByNameInOrgSpace
return
}
func (repo *FakeSpaceRepository) GetSummary() (space models.Space, apiErr error) {
space = repo.SummarySpace
return
}
func (repo *FakeSpaceRepository) Create(name string, orgGuid string) (space models.Space, apiErr error) {
if repo.CreateSpaceExists {
apiErr = errors.NewHttpError(400, errors.SPACE_EXISTS, "Space already exists")
return
}
repo.CreateSpaceName = name
repo.CreateSpaceOrgGuid = orgGuid
space = repo.CreateSpaceSpace
return
}
func (repo *FakeSpaceRepository) Rename(spaceGuid, newName string) (apiErr error) {
repo.RenameSpaceGuid = spaceGuid
repo.RenameNewName = newName
return
}
func (repo *FakeSpaceRepository) Delete(spaceGuid string) (apiErr error) {
repo.DeletedSpaceGuid = spaceGuid
return
}