diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2021-09-19 19:49:59 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-19 19:49:59 +0800 |
commit | a4bfef265d9e512830350635a0489c2cdcd6508f (patch) | |
tree | 1e3c2ec94276dfcb2f8ba73a2ac075ba39c4a34a /models/repo_permission_test.go | |
parent | 462306e263db5a809dbe2cdf62e99307aeff28de (diff) | |
download | gitea-a4bfef265d9e512830350635a0489c2cdcd6508f.tar.gz gitea-a4bfef265d9e512830350635a0489c2cdcd6508f.zip |
Move db related basic functions to models/db (#17075)
* Move db related basic functions to models/db
* Fix lint
* Fix lint
* Fix test
* Fix lint
* Fix lint
* revert unnecessary change
* Fix test
* Fix wrong replace string
* Use *Context
* Correct committer spelling and fix wrong replaced words
Co-authored-by: zeripath <art27@cantab.net>
Diffstat (limited to 'models/repo_permission_test.go')
-rw-r--r-- | models/repo_permission_test.go | 59 |
1 files changed, 30 insertions, 29 deletions
diff --git a/models/repo_permission_test.go b/models/repo_permission_test.go index 0f350e62aa..625e0dd205 100644 --- a/models/repo_permission_test.go +++ b/models/repo_permission_test.go @@ -7,18 +7,19 @@ package models import ( "testing" + "code.gitea.io/gitea/models/db" "github.com/stretchr/testify/assert" ) func TestRepoPermissionPublicNonOrgRepo(t *testing.T) { - assert.NoError(t, PrepareTestDatabase()) + assert.NoError(t, db.PrepareTestDatabase()) // public non-organization repo - repo := AssertExistsAndLoadBean(t, &Repository{ID: 4}).(*Repository) - assert.NoError(t, repo.getUnits(x)) + repo := db.AssertExistsAndLoadBean(t, &Repository{ID: 4}).(*Repository) + assert.NoError(t, repo.getUnits(db.DefaultContext().Engine())) // plain user - user := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User) + user := db.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User) perm, err := GetUserRepoPermission(repo, user) assert.NoError(t, err) for _, unit := range repo.Units { @@ -36,7 +37,7 @@ func TestRepoPermissionPublicNonOrgRepo(t *testing.T) { } // collaborator - collaborator := AssertExistsAndLoadBean(t, &User{ID: 4}).(*User) + collaborator := db.AssertExistsAndLoadBean(t, &User{ID: 4}).(*User) perm, err = GetUserRepoPermission(repo, collaborator) assert.NoError(t, err) for _, unit := range repo.Units { @@ -45,7 +46,7 @@ func TestRepoPermissionPublicNonOrgRepo(t *testing.T) { } // owner - owner := AssertExistsAndLoadBean(t, &User{ID: 5}).(*User) + owner := db.AssertExistsAndLoadBean(t, &User{ID: 5}).(*User) perm, err = GetUserRepoPermission(repo, owner) assert.NoError(t, err) for _, unit := range repo.Units { @@ -54,7 +55,7 @@ func TestRepoPermissionPublicNonOrgRepo(t *testing.T) { } // admin - admin := AssertExistsAndLoadBean(t, &User{ID: 1}).(*User) + admin := db.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User) perm, err = GetUserRepoPermission(repo, admin) assert.NoError(t, err) for _, unit := range repo.Units { @@ -64,14 +65,14 @@ func TestRepoPermissionPublicNonOrgRepo(t *testing.T) { } func TestRepoPermissionPrivateNonOrgRepo(t *testing.T) { - assert.NoError(t, PrepareTestDatabase()) + assert.NoError(t, db.PrepareTestDatabase()) // private non-organization repo - repo := AssertExistsAndLoadBean(t, &Repository{ID: 2}).(*Repository) - assert.NoError(t, repo.getUnits(x)) + repo := db.AssertExistsAndLoadBean(t, &Repository{ID: 2}).(*Repository) + assert.NoError(t, repo.getUnits(db.DefaultContext().Engine())) // plain user - user := AssertExistsAndLoadBean(t, &User{ID: 4}).(*User) + user := db.AssertExistsAndLoadBean(t, &User{ID: 4}).(*User) perm, err := GetUserRepoPermission(repo, user) assert.NoError(t, err) for _, unit := range repo.Units { @@ -97,7 +98,7 @@ func TestRepoPermissionPrivateNonOrgRepo(t *testing.T) { } // owner - owner := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User) + owner := db.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User) perm, err = GetUserRepoPermission(repo, owner) assert.NoError(t, err) for _, unit := range repo.Units { @@ -106,7 +107,7 @@ func TestRepoPermissionPrivateNonOrgRepo(t *testing.T) { } // admin - admin := AssertExistsAndLoadBean(t, &User{ID: 1}).(*User) + admin := db.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User) perm, err = GetUserRepoPermission(repo, admin) assert.NoError(t, err) for _, unit := range repo.Units { @@ -116,14 +117,14 @@ func TestRepoPermissionPrivateNonOrgRepo(t *testing.T) { } func TestRepoPermissionPublicOrgRepo(t *testing.T) { - assert.NoError(t, PrepareTestDatabase()) + assert.NoError(t, db.PrepareTestDatabase()) // public organization repo - repo := AssertExistsAndLoadBean(t, &Repository{ID: 32}).(*Repository) - assert.NoError(t, repo.getUnits(x)) + repo := db.AssertExistsAndLoadBean(t, &Repository{ID: 32}).(*Repository) + assert.NoError(t, repo.getUnits(db.DefaultContext().Engine())) // plain user - user := AssertExistsAndLoadBean(t, &User{ID: 5}).(*User) + user := db.AssertExistsAndLoadBean(t, &User{ID: 5}).(*User) perm, err := GetUserRepoPermission(repo, user) assert.NoError(t, err) for _, unit := range repo.Units { @@ -149,7 +150,7 @@ func TestRepoPermissionPublicOrgRepo(t *testing.T) { } // org member team owner - owner := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User) + owner := db.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User) perm, err = GetUserRepoPermission(repo, owner) assert.NoError(t, err) for _, unit := range repo.Units { @@ -158,7 +159,7 @@ func TestRepoPermissionPublicOrgRepo(t *testing.T) { } // org member team tester - member := AssertExistsAndLoadBean(t, &User{ID: 15}).(*User) + member := db.AssertExistsAndLoadBean(t, &User{ID: 15}).(*User) perm, err = GetUserRepoPermission(repo, member) assert.NoError(t, err) for _, unit := range repo.Units { @@ -168,7 +169,7 @@ func TestRepoPermissionPublicOrgRepo(t *testing.T) { assert.False(t, perm.CanWrite(UnitTypeCode)) // admin - admin := AssertExistsAndLoadBean(t, &User{ID: 1}).(*User) + admin := db.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User) perm, err = GetUserRepoPermission(repo, admin) assert.NoError(t, err) for _, unit := range repo.Units { @@ -178,14 +179,14 @@ func TestRepoPermissionPublicOrgRepo(t *testing.T) { } func TestRepoPermissionPrivateOrgRepo(t *testing.T) { - assert.NoError(t, PrepareTestDatabase()) + assert.NoError(t, db.PrepareTestDatabase()) // private organization repo - repo := AssertExistsAndLoadBean(t, &Repository{ID: 24}).(*Repository) - assert.NoError(t, repo.getUnits(x)) + repo := db.AssertExistsAndLoadBean(t, &Repository{ID: 24}).(*Repository) + assert.NoError(t, repo.getUnits(db.DefaultContext().Engine())) // plain user - user := AssertExistsAndLoadBean(t, &User{ID: 5}).(*User) + user := db.AssertExistsAndLoadBean(t, &User{ID: 5}).(*User) perm, err := GetUserRepoPermission(repo, user) assert.NoError(t, err) for _, unit := range repo.Units { @@ -211,7 +212,7 @@ func TestRepoPermissionPrivateOrgRepo(t *testing.T) { } // org member team owner - owner := AssertExistsAndLoadBean(t, &User{ID: 15}).(*User) + owner := db.AssertExistsAndLoadBean(t, &User{ID: 15}).(*User) perm, err = GetUserRepoPermission(repo, owner) assert.NoError(t, err) for _, unit := range repo.Units { @@ -220,7 +221,7 @@ func TestRepoPermissionPrivateOrgRepo(t *testing.T) { } // update team information and then check permission - team := AssertExistsAndLoadBean(t, &Team{ID: 5}).(*Team) + team := db.AssertExistsAndLoadBean(t, &Team{ID: 5}).(*Team) err = UpdateTeamUnits(team, nil) assert.NoError(t, err) perm, err = GetUserRepoPermission(repo, owner) @@ -231,7 +232,7 @@ func TestRepoPermissionPrivateOrgRepo(t *testing.T) { } // org member team tester - tester := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User) + tester := db.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User) perm, err = GetUserRepoPermission(repo, tester) assert.NoError(t, err) assert.True(t, perm.CanWrite(UnitTypeIssues)) @@ -239,7 +240,7 @@ func TestRepoPermissionPrivateOrgRepo(t *testing.T) { assert.False(t, perm.CanRead(UnitTypeCode)) // org member team reviewer - reviewer := AssertExistsAndLoadBean(t, &User{ID: 20}).(*User) + reviewer := db.AssertExistsAndLoadBean(t, &User{ID: 20}).(*User) perm, err = GetUserRepoPermission(repo, reviewer) assert.NoError(t, err) assert.False(t, perm.CanRead(UnitTypeIssues)) @@ -247,7 +248,7 @@ func TestRepoPermissionPrivateOrgRepo(t *testing.T) { assert.True(t, perm.CanRead(UnitTypeCode)) // admin - admin := AssertExistsAndLoadBean(t, &User{ID: 1}).(*User) + admin := db.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User) perm, err = GetUserRepoPermission(repo, admin) assert.NoError(t, err) for _, unit := range repo.Units { |