forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fake_user_repo.go
128 lines (103 loc) · 3.78 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
package fakes
import (
"github.com/cloudfoundry/cli/cf/errors"
"github.com/cloudfoundry/cli/cf/models"
)
type FakeUserRepository struct {
FindByUsernameUsername string
FindByUsernameUserFields models.UserFields
FindByUsernameNotFound bool
ListUsersOrganizationGuid string
ListUsersSpaceGuid string
ListUsersByRole map[string][]models.UserFields
CreateUserUsername string
CreateUserPassword string
CreateUserExists bool
CreateUserReturnsHttpError 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
ListUsersInOrgForRoleWithNoUAA_CallCount int
ListUsersInOrgForRole_CallCount int
ListUsersInSpaceForRoleWithNoUAA_CallCount int
ListUsersInSpaceForRole_CallCount int
}
func (repo *FakeUserRepository) FindByUsername(username string) (user models.UserFields, apiErr error) {
repo.FindByUsernameUsername = username
user = repo.FindByUsernameUserFields
if repo.FindByUsernameNotFound {
apiErr = errors.NewModelNotFoundError("User", "")
}
return
}
func (repo *FakeUserRepository) ListUsersInOrgForRoleWithNoUAA(orgGuid string, roleName string) ([]models.UserFields, error) {
repo.ListUsersOrganizationGuid = orgGuid
repo.ListUsersInOrgForRoleWithNoUAA_CallCount++
return repo.ListUsersByRole[roleName], nil
}
func (repo *FakeUserRepository) ListUsersInOrgForRole(orgGuid string, roleName string) ([]models.UserFields, error) {
repo.ListUsersOrganizationGuid = orgGuid
repo.ListUsersInOrgForRole_CallCount++
return repo.ListUsersByRole[roleName], nil
}
func (repo *FakeUserRepository) ListUsersInSpaceForRole(spaceGuid string, roleName string) ([]models.UserFields, error) {
repo.ListUsersSpaceGuid = spaceGuid
repo.ListUsersInSpaceForRole_CallCount++
return repo.ListUsersByRole[roleName], nil
}
func (repo *FakeUserRepository) ListUsersInSpaceForRoleWithNoUAA(spaceGuid string, roleName string) ([]models.UserFields, error) {
repo.ListUsersSpaceGuid = spaceGuid
repo.ListUsersInSpaceForRoleWithNoUAA_CallCount++
return repo.ListUsersByRole[roleName], nil
}
func (repo *FakeUserRepository) Create(username, password string) (apiErr error) {
repo.CreateUserUsername = username
repo.CreateUserPassword = password
if repo.CreateUserReturnsHttpError {
apiErr = errors.NewHttpError(403, "403", "Forbidden")
}
if repo.CreateUserExists {
apiErr = errors.NewModelAlreadyExistsError("User", username)
}
return
}
func (repo *FakeUserRepository) Delete(userGuid string) (apiErr error) {
repo.DeleteUserGuid = userGuid
return
}
func (repo *FakeUserRepository) SetOrgRole(userGuid, orgGuid, role string) (apiErr error) {
repo.SetOrgRoleUserGuid = userGuid
repo.SetOrgRoleOrganizationGuid = orgGuid
repo.SetOrgRoleRole = role
return
}
func (repo *FakeUserRepository) UnsetOrgRole(userGuid, orgGuid, role string) (apiErr error) {
repo.UnsetOrgRoleUserGuid = userGuid
repo.UnsetOrgRoleOrganizationGuid = orgGuid
repo.UnsetOrgRoleRole = role
return
}
func (repo *FakeUserRepository) SetSpaceRole(userGuid, spaceGuid, orgGuid, role string) (apiErr error) {
repo.SetSpaceRoleUserGuid = userGuid
repo.SetSpaceRoleOrgGuid = orgGuid
repo.SetSpaceRoleSpaceGuid = spaceGuid
repo.SetSpaceRoleRole = role
return
}
func (repo *FakeUserRepository) UnsetSpaceRole(userGuid, spaceGuid, role string) (apiErr error) {
repo.UnsetSpaceRoleUserGuid = userGuid
repo.UnsetSpaceRoleSpaceGuid = spaceGuid
repo.UnsetSpaceRoleRole = role
return
}