diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2021-11-16 16:53:21 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-16 16:53:21 +0800 |
commit | 81926d61db3dac223a75ea49eab893b25a089587 (patch) | |
tree | 627d2f19a008089f3a688e9a94a2cc8d2017afe2 /models/access_test.go | |
parent | 23bd7b1211a80aa3b0dcb60ec4a1c0089ff28dd4 (diff) | |
download | gitea-81926d61db3dac223a75ea49eab893b25a089587.tar.gz gitea-81926d61db3dac223a75ea49eab893b25a089587.zip |
Decouple unit test, remove intermediate `unittestbridge` package (#17662)
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Diffstat (limited to 'models/access_test.go')
-rw-r--r-- | models/access_test.go | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/models/access_test.go b/models/access_test.go index af799ebcde..96aa34edb6 100644 --- a/models/access_test.go +++ b/models/access_test.go @@ -15,21 +15,21 @@ import ( func TestAccessLevel(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) - user2 := db.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User) - user5 := db.AssertExistsAndLoadBean(t, &User{ID: 5}).(*User) - user29 := db.AssertExistsAndLoadBean(t, &User{ID: 29}).(*User) + user2 := unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User) + user5 := unittest.AssertExistsAndLoadBean(t, &User{ID: 5}).(*User) + user29 := unittest.AssertExistsAndLoadBean(t, &User{ID: 29}).(*User) // A public repository owned by User 2 - repo1 := db.AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository) + repo1 := unittest.AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository) assert.False(t, repo1.IsPrivate) // A private repository owned by Org 3 - repo3 := db.AssertExistsAndLoadBean(t, &Repository{ID: 3}).(*Repository) + repo3 := unittest.AssertExistsAndLoadBean(t, &Repository{ID: 3}).(*Repository) assert.True(t, repo3.IsPrivate) // Another public repository - repo4 := db.AssertExistsAndLoadBean(t, &Repository{ID: 4}).(*Repository) + repo4 := unittest.AssertExistsAndLoadBean(t, &Repository{ID: 4}).(*Repository) assert.False(t, repo4.IsPrivate) // org. owned private repo - repo24 := db.AssertExistsAndLoadBean(t, &Repository{ID: 24}).(*Repository) + repo24 := unittest.AssertExistsAndLoadBean(t, &Repository{ID: 24}).(*Repository) level, err := AccessLevel(user2, repo1) assert.NoError(t, err) @@ -66,13 +66,13 @@ func TestAccessLevel(t *testing.T) { func TestHasAccess(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) - user1 := db.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User) - user2 := db.AssertExistsAndLoadBean(t, &User{ID: 5}).(*User) + user1 := unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User) + user2 := unittest.AssertExistsAndLoadBean(t, &User{ID: 5}).(*User) // A public repository owned by User 2 - repo1 := db.AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository) + repo1 := unittest.AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository) assert.False(t, repo1.IsPrivate) // A private repository owned by Org 3 - repo2 := db.AssertExistsAndLoadBean(t, &Repository{ID: 3}).(*Repository) + repo2 := unittest.AssertExistsAndLoadBean(t, &Repository{ID: 3}).(*Repository) assert.True(t, repo2.IsPrivate) has, err := HasAccess(user1.ID, repo1) @@ -92,12 +92,12 @@ func TestHasAccess(t *testing.T) { func TestUser_GetRepositoryAccesses(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) - user1 := db.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User) + user1 := unittest.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User) accesses, err := user1.GetRepositoryAccesses() assert.NoError(t, err) assert.Len(t, accesses, 0) - user29 := db.AssertExistsAndLoadBean(t, &User{ID: 29}).(*User) + user29 := unittest.AssertExistsAndLoadBean(t, &User{ID: 29}).(*User) accesses, err = user29.GetRepositoryAccesses() assert.NoError(t, err) assert.Len(t, accesses, 2) @@ -106,17 +106,17 @@ func TestUser_GetRepositoryAccesses(t *testing.T) { func TestUser_GetAccessibleRepositories(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) - user1 := db.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User) + user1 := unittest.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User) repos, err := user1.GetAccessibleRepositories(0) assert.NoError(t, err) assert.Len(t, repos, 0) - user2 := db.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User) + user2 := unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User) repos, err = user2.GetAccessibleRepositories(0) assert.NoError(t, err) assert.Len(t, repos, 4) - user29 := db.AssertExistsAndLoadBean(t, &User{ID: 29}).(*User) + user29 := unittest.AssertExistsAndLoadBean(t, &User{ID: 29}).(*User) repos, err = user29.GetAccessibleRepositories(0) assert.NoError(t, err) assert.Len(t, repos, 2) @@ -125,7 +125,7 @@ func TestUser_GetAccessibleRepositories(t *testing.T) { func TestRepository_RecalculateAccesses(t *testing.T) { // test with organization repo assert.NoError(t, unittest.PrepareTestDatabase()) - repo1 := db.AssertExistsAndLoadBean(t, &Repository{ID: 3}).(*Repository) + repo1 := unittest.AssertExistsAndLoadBean(t, &Repository{ID: 3}).(*Repository) assert.NoError(t, repo1.GetOwner()) _, err := db.GetEngine(db.DefaultContext).Delete(&Collaboration{UserID: 2, RepoID: 3}) @@ -142,7 +142,7 @@ func TestRepository_RecalculateAccesses(t *testing.T) { func TestRepository_RecalculateAccesses2(t *testing.T) { // test with non-organization repo assert.NoError(t, unittest.PrepareTestDatabase()) - repo1 := db.AssertExistsAndLoadBean(t, &Repository{ID: 4}).(*Repository) + repo1 := unittest.AssertExistsAndLoadBean(t, &Repository{ID: 4}).(*Repository) assert.NoError(t, repo1.GetOwner()) _, err := db.GetEngine(db.DefaultContext).Delete(&Collaboration{UserID: 4, RepoID: 4}) @@ -156,8 +156,8 @@ func TestRepository_RecalculateAccesses2(t *testing.T) { func TestRepository_RecalculateAccesses3(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) - team5 := db.AssertExistsAndLoadBean(t, &Team{ID: 5}).(*Team) - user29 := db.AssertExistsAndLoadBean(t, &User{ID: 29}).(*User) + team5 := unittest.AssertExistsAndLoadBean(t, &Team{ID: 5}).(*Team) + user29 := unittest.AssertExistsAndLoadBean(t, &User{ID: 29}).(*User) has, err := db.GetEngine(db.DefaultContext).Get(&Access{UserID: 29, RepoID: 23}) assert.NoError(t, err) |