1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

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>
This commit is contained in:
Lunny Xiao
2021-09-19 19:49:59 +08:00
committed by GitHub
parent 462306e263
commit a4bfef265d
335 changed files with 4191 additions and 3654 deletions

View File

@@ -7,33 +7,34 @@ package models
import (
"testing"
"code.gitea.io/gitea/models/db"
"github.com/stretchr/testify/assert"
)
func TestLookupRepoRedirect(t *testing.T) {
assert.NoError(t, PrepareTestDatabase())
assert.NoError(t, db.PrepareTestDatabase())
repoID, err := LookupRepoRedirect(2, "oldrepo1")
assert.NoError(t, err)
assert.EqualValues(t, 1, repoID)
_, err = LookupRepoRedirect(NonexistentID, "doesnotexist")
_, err = LookupRepoRedirect(db.NonexistentID, "doesnotexist")
assert.True(t, IsErrRepoRedirectNotExist(err))
}
func TestNewRepoRedirect(t *testing.T) {
// redirect to a completely new name
assert.NoError(t, PrepareTestDatabase())
assert.NoError(t, db.PrepareTestDatabase())
repo := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
assert.NoError(t, newRepoRedirect(x, repo.OwnerID, repo.ID, repo.Name, "newreponame"))
repo := db.AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
assert.NoError(t, newRepoRedirect(db.DefaultContext().Engine(), repo.OwnerID, repo.ID, repo.Name, "newreponame"))
AssertExistsAndLoadBean(t, &RepoRedirect{
db.AssertExistsAndLoadBean(t, &RepoRedirect{
OwnerID: repo.OwnerID,
LowerName: repo.LowerName,
RedirectRepoID: repo.ID,
})
AssertExistsAndLoadBean(t, &RepoRedirect{
db.AssertExistsAndLoadBean(t, &RepoRedirect{
OwnerID: repo.OwnerID,
LowerName: "oldrepo1",
RedirectRepoID: repo.ID,
@@ -42,17 +43,17 @@ func TestNewRepoRedirect(t *testing.T) {
func TestNewRepoRedirect2(t *testing.T) {
// redirect to previously used name
assert.NoError(t, PrepareTestDatabase())
assert.NoError(t, db.PrepareTestDatabase())
repo := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
assert.NoError(t, newRepoRedirect(x, repo.OwnerID, repo.ID, repo.Name, "oldrepo1"))
repo := db.AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
assert.NoError(t, newRepoRedirect(db.DefaultContext().Engine(), repo.OwnerID, repo.ID, repo.Name, "oldrepo1"))
AssertExistsAndLoadBean(t, &RepoRedirect{
db.AssertExistsAndLoadBean(t, &RepoRedirect{
OwnerID: repo.OwnerID,
LowerName: repo.LowerName,
RedirectRepoID: repo.ID,
})
AssertNotExistsBean(t, &RepoRedirect{
db.AssertNotExistsBean(t, &RepoRedirect{
OwnerID: repo.OwnerID,
LowerName: "oldrepo1",
RedirectRepoID: repo.ID,
@@ -61,12 +62,12 @@ func TestNewRepoRedirect2(t *testing.T) {
func TestNewRepoRedirect3(t *testing.T) {
// redirect for a previously-unredirected repo
assert.NoError(t, PrepareTestDatabase())
assert.NoError(t, db.PrepareTestDatabase())
repo := AssertExistsAndLoadBean(t, &Repository{ID: 2}).(*Repository)
assert.NoError(t, newRepoRedirect(x, repo.OwnerID, repo.ID, repo.Name, "newreponame"))
repo := db.AssertExistsAndLoadBean(t, &Repository{ID: 2}).(*Repository)
assert.NoError(t, newRepoRedirect(db.DefaultContext().Engine(), repo.OwnerID, repo.ID, repo.Name, "newreponame"))
AssertExistsAndLoadBean(t, &RepoRedirect{
db.AssertExistsAndLoadBean(t, &RepoRedirect{
OwnerID: repo.OwnerID,
LowerName: repo.LowerName,
RedirectRepoID: repo.ID,