forked from forgejo/forgejo
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:
parent
462306e263
commit
a4bfef265d
335 changed files with 4191 additions and 3654 deletions
|
@ -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})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue