aboutsummaryrefslogtreecommitdiffstats
path: root/models/admin_test.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2021-09-19 19:49:59 +0800
committerGitHub <noreply@github.com>2021-09-19 19:49:59 +0800
commita4bfef265d9e512830350635a0489c2cdcd6508f (patch)
tree1e3c2ec94276dfcb2f8ba73a2ac075ba39c4a34a /models/admin_test.go
parent462306e263db5a809dbe2cdf62e99307aeff28de (diff)
downloadgitea-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/admin_test.go')
-rw-r--r--models/admin_test.go65
1 files changed, 33 insertions, 32 deletions
diff --git a/models/admin_test.go b/models/admin_test.go
index b4383cb2d3..316ed5cb68 100644
--- a/models/admin_test.go
+++ b/models/admin_test.go
@@ -7,6 +7,7 @@ package models
import (
"testing"
+ "code.gitea.io/gitea/models/db"
"github.com/stretchr/testify/assert"
)
@@ -19,38 +20,38 @@ func TestNotice_TrStr(t *testing.T) {
}
func TestCreateNotice(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
noticeBean := &Notice{
Type: NoticeRepository,
Description: "test description",
}
- AssertNotExistsBean(t, noticeBean)
+ db.AssertNotExistsBean(t, noticeBean)
assert.NoError(t, CreateNotice(noticeBean.Type, noticeBean.Description))
- AssertExistsAndLoadBean(t, noticeBean)
+ db.AssertExistsAndLoadBean(t, noticeBean)
}
func TestCreateRepositoryNotice(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
noticeBean := &Notice{
Type: NoticeRepository,
Description: "test description",
}
- AssertNotExistsBean(t, noticeBean)
+ db.AssertNotExistsBean(t, noticeBean)
assert.NoError(t, CreateRepositoryNotice(noticeBean.Description))
- AssertExistsAndLoadBean(t, noticeBean)
+ db.AssertExistsAndLoadBean(t, noticeBean)
}
// TODO TestRemoveAllWithNotice
func TestCountNotices(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
assert.Equal(t, int64(3), CountNotices())
}
func TestNotices(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
notices, err := Notices(1, 2)
assert.NoError(t, err)
@@ -67,47 +68,47 @@ func TestNotices(t *testing.T) {
}
func TestDeleteNotice(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
- AssertExistsAndLoadBean(t, &Notice{ID: 3})
+ db.AssertExistsAndLoadBean(t, &Notice{ID: 3})
assert.NoError(t, DeleteNotice(3))
- AssertNotExistsBean(t, &Notice{ID: 3})
+ db.AssertNotExistsBean(t, &Notice{ID: 3})
}
func TestDeleteNotices(t *testing.T) {
// delete a non-empty range
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
- AssertExistsAndLoadBean(t, &Notice{ID: 1})
- AssertExistsAndLoadBean(t, &Notice{ID: 2})
- AssertExistsAndLoadBean(t, &Notice{ID: 3})
+ db.AssertExistsAndLoadBean(t, &Notice{ID: 1})
+ db.AssertExistsAndLoadBean(t, &Notice{ID: 2})
+ db.AssertExistsAndLoadBean(t, &Notice{ID: 3})
assert.NoError(t, DeleteNotices(1, 2))
- AssertNotExistsBean(t, &Notice{ID: 1})
- AssertNotExistsBean(t, &Notice{ID: 2})
- AssertExistsAndLoadBean(t, &Notice{ID: 3})
+ db.AssertNotExistsBean(t, &Notice{ID: 1})
+ db.AssertNotExistsBean(t, &Notice{ID: 2})
+ db.AssertExistsAndLoadBean(t, &Notice{ID: 3})
}
func TestDeleteNotices2(t *testing.T) {
// delete an empty range
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
- AssertExistsAndLoadBean(t, &Notice{ID: 1})
- AssertExistsAndLoadBean(t, &Notice{ID: 2})
- AssertExistsAndLoadBean(t, &Notice{ID: 3})
+ db.AssertExistsAndLoadBean(t, &Notice{ID: 1})
+ db.AssertExistsAndLoadBean(t, &Notice{ID: 2})
+ db.AssertExistsAndLoadBean(t, &Notice{ID: 3})
assert.NoError(t, DeleteNotices(3, 2))
- AssertExistsAndLoadBean(t, &Notice{ID: 1})
- AssertExistsAndLoadBean(t, &Notice{ID: 2})
- AssertExistsAndLoadBean(t, &Notice{ID: 3})
+ db.AssertExistsAndLoadBean(t, &Notice{ID: 1})
+ db.AssertExistsAndLoadBean(t, &Notice{ID: 2})
+ db.AssertExistsAndLoadBean(t, &Notice{ID: 3})
}
func TestDeleteNoticesByIDs(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
- AssertExistsAndLoadBean(t, &Notice{ID: 1})
- AssertExistsAndLoadBean(t, &Notice{ID: 2})
- AssertExistsAndLoadBean(t, &Notice{ID: 3})
+ db.AssertExistsAndLoadBean(t, &Notice{ID: 1})
+ db.AssertExistsAndLoadBean(t, &Notice{ID: 2})
+ db.AssertExistsAndLoadBean(t, &Notice{ID: 3})
assert.NoError(t, DeleteNoticesByIDs([]int64{1, 3}))
- AssertNotExistsBean(t, &Notice{ID: 1})
- AssertExistsAndLoadBean(t, &Notice{ID: 2})
- AssertNotExistsBean(t, &Notice{ID: 3})
+ db.AssertNotExistsBean(t, &Notice{ID: 1})
+ db.AssertExistsAndLoadBean(t, &Notice{ID: 2})
+ db.AssertNotExistsBean(t, &Notice{ID: 3})
}