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
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
335 changed files with 4191 additions and 3654 deletions

View file

@ -7,11 +7,12 @@ package models
import (
"testing"
"code.gitea.io/gitea/models/db"
"github.com/stretchr/testify/assert"
)
func TestIncreaseDownloadCount(t *testing.T) {
assert.NoError(t, PrepareTestDatabase())
assert.NoError(t, db.PrepareTestDatabase())
attachment, err := GetAttachmentByUUID("a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11")
assert.NoError(t, err)
@ -27,7 +28,7 @@ func TestIncreaseDownloadCount(t *testing.T) {
}
func TestGetByCommentOrIssueID(t *testing.T) {
assert.NoError(t, PrepareTestDatabase())
assert.NoError(t, db.PrepareTestDatabase())
// count of attachments from issue ID
attachments, err := GetAttachmentsByIssueID(1)
@ -40,7 +41,7 @@ func TestGetByCommentOrIssueID(t *testing.T) {
}
func TestDeleteAttachments(t *testing.T) {
assert.NoError(t, PrepareTestDatabase())
assert.NoError(t, db.PrepareTestDatabase())
count, err := DeleteAttachmentsByIssue(4, false)
assert.NoError(t, err)
@ -60,7 +61,7 @@ func TestDeleteAttachments(t *testing.T) {
}
func TestGetAttachmentByID(t *testing.T) {
assert.NoError(t, PrepareTestDatabase())
assert.NoError(t, db.PrepareTestDatabase())
attach, err := GetAttachmentByID(1)
assert.NoError(t, err)
@ -76,7 +77,7 @@ func TestAttachment_DownloadURL(t *testing.T) {
}
func TestUpdateAttachment(t *testing.T) {
assert.NoError(t, PrepareTestDatabase())
assert.NoError(t, db.PrepareTestDatabase())
attach, err := GetAttachmentByID(1)
assert.NoError(t, err)
@ -85,13 +86,13 @@ func TestUpdateAttachment(t *testing.T) {
attach.Name = "new_name"
assert.NoError(t, UpdateAttachment(attach))
AssertExistsAndLoadBean(t, &Attachment{Name: "new_name"})
db.AssertExistsAndLoadBean(t, &Attachment{Name: "new_name"})
}
func TestGetAttachmentsByUUIDs(t *testing.T) {
assert.NoError(t, PrepareTestDatabase())
assert.NoError(t, db.PrepareTestDatabase())
attachList, err := GetAttachmentsByUUIDs(DefaultDBContext(), []string{"a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11", "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a17", "not-existing-uuid"})
attachList, err := GetAttachmentsByUUIDs(db.DefaultContext(), []string{"a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11", "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a17", "not-existing-uuid"})
assert.NoError(t, err)
assert.Len(t, attachList, 2)
assert.Equal(t, "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11", attachList[0].UUID)
@ -101,7 +102,7 @@ func TestGetAttachmentsByUUIDs(t *testing.T) {
}
func TestLinkedRepository(t *testing.T) {
assert.NoError(t, PrepareTestDatabase())
assert.NoError(t, db.PrepareTestDatabase())
testCases := []struct {
name string
attachID int64