diff options
author | Ethan Koenig <etk39@cornell.edu> | 2017-05-20 04:48:22 -0400 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2017-05-20 16:48:22 +0800 |
commit | cf02cd7ba0c94165743660cf30f0cbb5a73a385e (patch) | |
tree | 6f09dce7c705041df1e042750137e379b0af66dc /models/user_test.go | |
parent | 85a73965256411c36ecc050eeb7967d3c8ef20d5 (diff) | |
download | gitea-cf02cd7ba0c94165743660cf30f0cbb5a73a385e.tar.gz gitea-cf02cd7ba0c94165743660cf30f0cbb5a73a385e.zip |
Fix and test for delete user (#1713)
* Fix and test for delete user
* Run updates in batches
* Unit test
Diffstat (limited to 'models/user_test.go')
-rw-r--r-- | models/user_test.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/models/user_test.go b/models/user_test.go index b10ed9dcba..a16f979530 100644 --- a/models/user_test.go +++ b/models/user_test.go @@ -36,5 +36,36 @@ func TestCanCreateOrganization(t *testing.T) { user.AllowCreateOrganization = true assert.True(t, admin.CanCreateOrganization()) assert.False(t, user.CanCreateOrganization()) +} + +func TestDeleteUser(t *testing.T) { + test := func(userID int64) { + assert.NoError(t, PrepareTestDatabase()) + user := AssertExistsAndLoadBean(t, &User{ID: userID}).(*User) + + ownedRepos := make([]*Repository, 0, 10) + assert.NoError(t, x.Find(&ownedRepos, &Repository{OwnerID: userID})) + if len(ownedRepos) > 0 { + err := DeleteUser(user) + assert.Error(t, err) + assert.True(t, IsErrUserOwnRepos(err)) + return + } + orgUsers := make([]*OrgUser, 0, 10) + assert.NoError(t, x.Find(&orgUsers, &OrgUser{UID: userID})) + for _, orgUser := range orgUsers { + if err := RemoveOrgUser(orgUser.OrgID, orgUser.UID); err != nil { + assert.True(t, IsErrLastOrgOwner(err)) + return + } + } + assert.NoError(t, DeleteUser(user)) + AssertNotExistsBean(t, &User{ID: userID}) + CheckConsistencyFor(t, &User{}, &Repository{}) + } + test(2) + test(4) + test(8) + test(11) } |