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_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_test.go')
-rw-r--r-- | models/repo_test.go | 45 |
1 files changed, 23 insertions, 22 deletions
diff --git a/models/repo_test.go b/models/repo_test.go index 28eb9baa17..2467b63840 100644 --- a/models/repo_test.go +++ b/models/repo_test.go @@ -12,13 +12,14 @@ import ( "image/png" "testing" + "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/modules/markup" "github.com/stretchr/testify/assert" ) func TestMetas(t *testing.T) { - assert.NoError(t, PrepareTestDatabase()) + assert.NoError(t, db.PrepareTestDatabase()) repo := &Repository{Name: "testRepo"} repo.Owner = &User{Name: "testOwner"} @@ -66,7 +67,7 @@ func TestMetas(t *testing.T) { } func TestGetRepositoryCount(t *testing.T) { - assert.NoError(t, PrepareTestDatabase()) + assert.NoError(t, db.PrepareTestDatabase()) count, err1 := GetRepositoryCount(&User{ID: int64(10)}) privateCount, err2 := GetPrivateRepositoryCount(&User{ID: int64(10)}) @@ -79,7 +80,7 @@ func TestGetRepositoryCount(t *testing.T) { } func TestGetPublicRepositoryCount(t *testing.T) { - assert.NoError(t, PrepareTestDatabase()) + assert.NoError(t, db.PrepareTestDatabase()) count, err := GetPublicRepositoryCount(&User{ID: int64(10)}) assert.NoError(t, err) @@ -87,7 +88,7 @@ func TestGetPublicRepositoryCount(t *testing.T) { } func TestGetPrivateRepositoryCount(t *testing.T) { - assert.NoError(t, PrepareTestDatabase()) + assert.NoError(t, db.PrepareTestDatabase()) count, err := GetPrivateRepositoryCount(&User{ID: int64(10)}) assert.NoError(t, err) @@ -95,7 +96,7 @@ func TestGetPrivateRepositoryCount(t *testing.T) { } func TestUpdateRepositoryVisibilityChanged(t *testing.T) { - assert.NoError(t, PrepareTestDatabase()) + assert.NoError(t, db.PrepareTestDatabase()) // Get sample repo and change visibility repo, err := GetRepositoryByID(9) @@ -108,14 +109,14 @@ func TestUpdateRepositoryVisibilityChanged(t *testing.T) { // Check visibility of action has become private act := Action{} - _, err = x.ID(3).Get(&act) + _, err = db.DefaultContext().Engine().ID(3).Get(&act) assert.NoError(t, err) assert.True(t, act.IsPrivate) } func TestGetUserFork(t *testing.T) { - assert.NoError(t, PrepareTestDatabase()) + assert.NoError(t, db.PrepareTestDatabase()) // User13 has repo 11 forked from repo10 repo, err := GetRepositoryByID(10) @@ -134,8 +135,8 @@ func TestGetUserFork(t *testing.T) { } func TestRepoAPIURL(t *testing.T) { - assert.NoError(t, PrepareTestDatabase()) - repo := AssertExistsAndLoadBean(t, &Repository{ID: 10}).(*Repository) + assert.NoError(t, db.PrepareTestDatabase()) + repo := db.AssertExistsAndLoadBean(t, &Repository{ID: 10}).(*Repository) assert.Equal(t, "https://try.gitea.io/api/v1/repos/user12/repo10", repo.APIURL()) } @@ -146,8 +147,8 @@ func TestUploadAvatar(t *testing.T) { var buff bytes.Buffer png.Encode(&buff, myImage) - assert.NoError(t, PrepareTestDatabase()) - repo := AssertExistsAndLoadBean(t, &Repository{ID: 10}).(*Repository) + assert.NoError(t, db.PrepareTestDatabase()) + repo := db.AssertExistsAndLoadBean(t, &Repository{ID: 10}).(*Repository) err := repo.UploadAvatar(buff.Bytes()) assert.NoError(t, err) @@ -160,8 +161,8 @@ func TestUploadBigAvatar(t *testing.T) { var buff bytes.Buffer png.Encode(&buff, myImage) - assert.NoError(t, PrepareTestDatabase()) - repo := AssertExistsAndLoadBean(t, &Repository{ID: 10}).(*Repository) + assert.NoError(t, db.PrepareTestDatabase()) + repo := db.AssertExistsAndLoadBean(t, &Repository{ID: 10}).(*Repository) err := repo.UploadAvatar(buff.Bytes()) assert.Error(t, err) @@ -173,8 +174,8 @@ func TestDeleteAvatar(t *testing.T) { var buff bytes.Buffer png.Encode(&buff, myImage) - assert.NoError(t, PrepareTestDatabase()) - repo := AssertExistsAndLoadBean(t, &Repository{ID: 10}).(*Repository) + assert.NoError(t, db.PrepareTestDatabase()) + repo := db.AssertExistsAndLoadBean(t, &Repository{ID: 10}).(*Repository) err := repo.UploadAvatar(buff.Bytes()) assert.NoError(t, err) @@ -186,37 +187,37 @@ func TestDeleteAvatar(t *testing.T) { } func TestDoctorUserStarNum(t *testing.T) { - assert.NoError(t, PrepareTestDatabase()) + assert.NoError(t, db.PrepareTestDatabase()) assert.NoError(t, DoctorUserStarNum()) } func TestRepoGetReviewers(t *testing.T) { - assert.NoError(t, PrepareTestDatabase()) + assert.NoError(t, db.PrepareTestDatabase()) // test public repo - repo1 := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository) + repo1 := db.AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository) reviewers, err := repo1.GetReviewers(2, 2) assert.NoError(t, err) assert.Len(t, reviewers, 4) // test private repo - repo2 := AssertExistsAndLoadBean(t, &Repository{ID: 2}).(*Repository) + repo2 := db.AssertExistsAndLoadBean(t, &Repository{ID: 2}).(*Repository) reviewers, err = repo2.GetReviewers(2, 2) assert.NoError(t, err) assert.Empty(t, reviewers) } func TestRepoGetReviewerTeams(t *testing.T) { - assert.NoError(t, PrepareTestDatabase()) + assert.NoError(t, db.PrepareTestDatabase()) - repo2 := AssertExistsAndLoadBean(t, &Repository{ID: 2}).(*Repository) + repo2 := db.AssertExistsAndLoadBean(t, &Repository{ID: 2}).(*Repository) teams, err := repo2.GetReviewerTeams() assert.NoError(t, err) assert.Empty(t, teams) - repo3 := AssertExistsAndLoadBean(t, &Repository{ID: 3}).(*Repository) + repo3 := db.AssertExistsAndLoadBean(t, &Repository{ID: 3}).(*Repository) teams, err = repo3.GetReviewerTeams() assert.NoError(t, err) assert.Len(t, teams, 2) |