github.com/rakutentech/cli@v6.12.5-0.20151006231303-24468b65536e+incompatible/cf/api/fakes/fake_user_repo.go (about) 1 package fakes 2 3 import ( 4 "github.com/cloudfoundry/cli/cf/errors" 5 "github.com/cloudfoundry/cli/cf/models" 6 ) 7 8 type FakeUserRepository struct { 9 FindByUsernameUsername string 10 FindByUsernameUserFields models.UserFields 11 FindByUsernameNotFound bool 12 13 ListUsersOrganizationGuid string 14 ListUsersSpaceGuid string 15 ListUsersByRole map[string][]models.UserFields 16 17 CreateUserUsername string 18 CreateUserPassword string 19 CreateUserExists bool 20 CreateUserReturnsHttpError bool 21 22 DeleteUserGuid string 23 24 SetOrgRoleUserGuid string 25 SetOrgRoleOrganizationGuid string 26 SetOrgRoleRole string 27 28 UnsetOrgRoleUserGuid string 29 UnsetOrgRoleOrganizationGuid string 30 UnsetOrgRoleRole string 31 32 SetSpaceRoleUserGuid string 33 SetSpaceRoleOrgGuid string 34 SetSpaceRoleSpaceGuid string 35 SetSpaceRoleRole string 36 37 UnsetSpaceRoleUserGuid string 38 UnsetSpaceRoleSpaceGuid string 39 UnsetSpaceRoleRole string 40 41 ListUsersInOrgForRoleWithNoUAA_CallCount int 42 ListUsersInOrgForRole_CallCount int 43 ListUsersInSpaceForRoleWithNoUAA_CallCount int 44 ListUsersInSpaceForRole_CallCount int 45 } 46 47 func (repo *FakeUserRepository) FindByUsername(username string) (user models.UserFields, apiErr error) { 48 repo.FindByUsernameUsername = username 49 user = repo.FindByUsernameUserFields 50 51 if repo.FindByUsernameNotFound { 52 apiErr = errors.NewModelNotFoundError("User", "") 53 } 54 55 return 56 } 57 58 func (repo *FakeUserRepository) ListUsersInOrgForRoleWithNoUAA(orgGuid string, roleName string) ([]models.UserFields, error) { 59 repo.ListUsersOrganizationGuid = orgGuid 60 repo.ListUsersInOrgForRoleWithNoUAA_CallCount++ 61 return repo.ListUsersByRole[roleName], nil 62 } 63 64 func (repo *FakeUserRepository) ListUsersInOrgForRole(orgGuid string, roleName string) ([]models.UserFields, error) { 65 repo.ListUsersOrganizationGuid = orgGuid 66 repo.ListUsersInOrgForRole_CallCount++ 67 return repo.ListUsersByRole[roleName], nil 68 } 69 70 func (repo *FakeUserRepository) ListUsersInSpaceForRole(spaceGuid string, roleName string) ([]models.UserFields, error) { 71 repo.ListUsersSpaceGuid = spaceGuid 72 repo.ListUsersInSpaceForRole_CallCount++ 73 return repo.ListUsersByRole[roleName], nil 74 } 75 76 func (repo *FakeUserRepository) ListUsersInSpaceForRoleWithNoUAA(spaceGuid string, roleName string) ([]models.UserFields, error) { 77 repo.ListUsersSpaceGuid = spaceGuid 78 repo.ListUsersInSpaceForRoleWithNoUAA_CallCount++ 79 return repo.ListUsersByRole[roleName], nil 80 } 81 82 func (repo *FakeUserRepository) Create(username, password string) (apiErr error) { 83 repo.CreateUserUsername = username 84 repo.CreateUserPassword = password 85 86 if repo.CreateUserReturnsHttpError { 87 apiErr = errors.NewHttpError(403, "403", "Forbidden") 88 } 89 if repo.CreateUserExists { 90 apiErr = errors.NewModelAlreadyExistsError("User", username) 91 } 92 93 return 94 } 95 96 func (repo *FakeUserRepository) Delete(userGuid string) (apiErr error) { 97 repo.DeleteUserGuid = userGuid 98 return 99 } 100 101 func (repo *FakeUserRepository) SetOrgRole(userGuid, orgGuid, role string) (apiErr error) { 102 repo.SetOrgRoleUserGuid = userGuid 103 repo.SetOrgRoleOrganizationGuid = orgGuid 104 repo.SetOrgRoleRole = role 105 return 106 } 107 108 func (repo *FakeUserRepository) UnsetOrgRole(userGuid, orgGuid, role string) (apiErr error) { 109 repo.UnsetOrgRoleUserGuid = userGuid 110 repo.UnsetOrgRoleOrganizationGuid = orgGuid 111 repo.UnsetOrgRoleRole = role 112 return 113 } 114 115 func (repo *FakeUserRepository) SetSpaceRole(userGuid, spaceGuid, orgGuid, role string) (apiErr error) { 116 repo.SetSpaceRoleUserGuid = userGuid 117 repo.SetSpaceRoleOrgGuid = orgGuid 118 repo.SetSpaceRoleSpaceGuid = spaceGuid 119 repo.SetSpaceRoleRole = role 120 return 121 } 122 123 func (repo *FakeUserRepository) UnsetSpaceRole(userGuid, spaceGuid, role string) (apiErr error) { 124 repo.UnsetSpaceRoleUserGuid = userGuid 125 repo.UnsetSpaceRoleSpaceGuid = spaceGuid 126 repo.UnsetSpaceRoleRole = role 127 return 128 }