forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fake_user_repo.go
133 lines (106 loc) · 3.63 KB
/
fake_user_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
123
124
125
126
127
128
129
130
131
132
133
package api
import (
"cf"
"cf/net"
)
type FakeUserRepository struct {
FindByUsernameUsername string
FindByUsernameUserFields cf.UserFields
FindByUsernameNotFound bool
ListUsersOrganizationGuid string
ListUsersSpaceGuid string
ListUsersByRole map[string][]cf.UserFields
CreateUserUsername string
CreateUserPassword string
CreateUserExists bool
DeleteUserGuid string
SetOrgRoleUserGuid string
SetOrgRoleOrganizationGuid string
SetOrgRoleRole string
UnsetOrgRoleUserGuid string
UnsetOrgRoleOrganizationGuid string
UnsetOrgRoleRole string
SetSpaceRoleUserGuid string
SetSpaceRoleOrgGuid string
SetSpaceRoleSpaceGuid string
SetSpaceRoleRole string
UnsetSpaceRoleUserGuid string
UnsetSpaceRoleSpaceGuid string
UnsetSpaceRoleRole string
}
func (repo *FakeUserRepository) FindByUsername(username string) (user cf.UserFields, apiResponse net.ApiResponse) {
repo.FindByUsernameUsername = username
user = repo.FindByUsernameUserFields
if repo.FindByUsernameNotFound {
apiResponse = net.NewNotFoundApiResponse("UserFields not found")
}
return
}
func (repo *FakeUserRepository) ListUsersInOrgForRole(orgGuid string, roleName string, stop chan bool) (usersChan chan []cf.UserFields, statusChan chan net.ApiResponse) {
repo.ListUsersOrganizationGuid = orgGuid
return repo.listUsersForRole(roleName, stop)
}
func (repo *FakeUserRepository) ListUsersInSpaceForRole(spaceGuid string, roleName string, stop chan bool) (usersChan chan []cf.UserFields, statusChan chan net.ApiResponse) {
repo.ListUsersSpaceGuid = spaceGuid
return repo.listUsersForRole(roleName, stop)
}
func (repo *FakeUserRepository) listUsersForRole(roleName string, stop chan bool) (usersChan chan []cf.UserFields, statusChan chan net.ApiResponse) {
usersChan = make(chan []cf.UserFields, 4)
statusChan = make(chan net.ApiResponse, 1)
go func() {
usersCount := len(repo.ListUsersByRole[roleName])
for i := 0; i < usersCount; i += 2 {
select {
case <-stop:
break
default:
if usersCount-i > 1 {
usersChan <- repo.ListUsersByRole[roleName][i : i+2]
} else {
usersChan <- repo.ListUsersByRole[roleName][i:]
}
}
}
close(usersChan)
close(statusChan)
cf.WaitForClose(stop)
}()
return
}
func (repo *FakeUserRepository) Create(username, password string) (apiResponse net.ApiResponse) {
repo.CreateUserUsername = username
repo.CreateUserPassword = password
if repo.CreateUserExists {
apiResponse = net.NewApiResponse("UserFields already exists", cf.USER_EXISTS, 400)
}
return
}
func (repo *FakeUserRepository) Delete(userGuid string) (apiResponse net.ApiResponse) {
repo.DeleteUserGuid = userGuid
return
}
func (repo *FakeUserRepository) SetOrgRole(userGuid, orgGuid, role string) (apiResponse net.ApiResponse) {
repo.SetOrgRoleUserGuid = userGuid
repo.SetOrgRoleOrganizationGuid = orgGuid
repo.SetOrgRoleRole = role
return
}
func (repo *FakeUserRepository) UnsetOrgRole(userGuid, orgGuid, role string) (apiResponse net.ApiResponse) {
repo.UnsetOrgRoleUserGuid = userGuid
repo.UnsetOrgRoleOrganizationGuid = orgGuid
repo.UnsetOrgRoleRole = role
return
}
func (repo *FakeUserRepository) SetSpaceRole(userGuid, spaceGuid, orgGuid, role string) (apiResponse net.ApiResponse) {
repo.SetSpaceRoleUserGuid = userGuid
repo.SetSpaceRoleOrgGuid = orgGuid
repo.SetSpaceRoleSpaceGuid = spaceGuid
repo.SetSpaceRoleRole = role
return
}
func (repo *FakeUserRepository) UnsetSpaceRole(userGuid, spaceGuid, role string) (apiResponse net.ApiResponse) {
repo.UnsetSpaceRoleUserGuid = userGuid
repo.UnsetSpaceRoleSpaceGuid = spaceGuid
repo.UnsetSpaceRoleRole = role
return
}