forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fake_space_repo.go
122 lines (97 loc) · 2.68 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package api
import (
"cf"
"cf/net"
)
type FakeSpaceRepository struct {
CurrentSpace cf.Space
Spaces []cf.Space
FindByNameName string
FindByNameSpace cf.Space
FindByNameErr bool
FindByNameNotFound bool
FindByNameInOrgName string
FindByNameInOrgOrgGuid string
FindByNameInOrgSpace cf.Space
SummarySpace cf.Space
CreateSpaceName string
CreateSpaceOrgGuid string
CreateSpaceExists bool
CreateSpaceSpace cf.Space
RenameSpaceGuid string
RenameNewName string
DeletedSpaceGuid string
}
func (repo FakeSpaceRepository) GetCurrentSpace() (space cf.Space) {
return repo.CurrentSpace
}
func (repo FakeSpaceRepository) ListSpaces(stop chan bool) (spacesChan chan []cf.Space, statusChan chan net.ApiResponse) {
spacesChan = make(chan []cf.Space, 4)
statusChan = make(chan net.ApiResponse, 1)
go func() {
spacesCount := len(repo.Spaces)
for i := 0; i < spacesCount; i += 2 {
select {
case <-stop:
break
default:
if spacesCount-i > 1 {
spacesChan <- repo.Spaces[i : i+2]
} else {
spacesChan <- repo.Spaces[i:]
}
}
}
close(spacesChan)
close(statusChan)
cf.WaitForClose(stop)
}()
return
}
func (repo *FakeSpaceRepository) FindByName(name string) (space cf.Space, apiResponse net.ApiResponse) {
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 {
apiResponse = net.NewApiResponseWithMessage("Error finding space by name.")
}
if repo.FindByNameNotFound {
apiResponse = net.NewNotFoundApiResponse("%s %s not found", "Space", name)
}
return
}
func (repo *FakeSpaceRepository) FindByNameInOrg(name, orgGuid string) (space cf.Space, apiResponse net.ApiResponse) {
repo.FindByNameInOrgName = name
repo.FindByNameInOrgOrgGuid = orgGuid
space = repo.FindByNameInOrgSpace
return
}
func (repo *FakeSpaceRepository) GetSummary() (space cf.Space, apiResponse net.ApiResponse) {
space = repo.SummarySpace
return
}
func (repo *FakeSpaceRepository) Create(name string, orgGuid string) (space cf.Space, apiResponse net.ApiResponse) {
if repo.CreateSpaceExists {
apiResponse = net.NewApiResponse("Space already exists", cf.SPACE_EXISTS, 400)
return
}
repo.CreateSpaceName = name
repo.CreateSpaceOrgGuid = orgGuid
space = repo.CreateSpaceSpace
return
}
func (repo *FakeSpaceRepository) Rename(spaceGuid, newName string) (apiResponse net.ApiResponse) {
repo.RenameSpaceGuid = spaceGuid
repo.RenameNewName = newName
return
}
func (repo *FakeSpaceRepository) Delete(spaceGuid string) (apiResponse net.ApiResponse) {
repo.DeletedSpaceGuid = spaceGuid
return
}