Decouple unit test code from business code (#17623)
This commit is contained in:
@ -10,7 +10,7 @@ import (
|
||||
"path/filepath"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
)
|
||||
|
||||
// To generate derivative fixtures, execute the following from Gitea's repository base dir:
|
||||
@ -31,13 +31,13 @@ var (
|
||||
func main() {
|
||||
pathToGiteaRoot := "."
|
||||
fixturesDir = filepath.Join(pathToGiteaRoot, "models", "fixtures")
|
||||
if err := db.CreateTestEngine(db.FixturesOptions{
|
||||
if err := unittest.CreateTestEngine(unittest.FixturesOptions{
|
||||
Dir: fixturesDir,
|
||||
}); err != nil {
|
||||
fmt.Printf("CreateTestEngine: %+v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if err := db.PrepareTestDatabase(); err != nil {
|
||||
if err := unittest.PrepareTestDatabase(); err != nil {
|
||||
fmt.Printf("PrepareTestDatabase: %+v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ import (
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
gitea_git "code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/markup"
|
||||
"code.gitea.io/gitea/modules/markup/external"
|
||||
@ -99,8 +100,8 @@ func runPR() {
|
||||
})
|
||||
db.HasEngine = true
|
||||
//x.ShowSQL(true)
|
||||
err = db.InitFixtures(
|
||||
db.FixturesOptions{
|
||||
err = unittest.InitFixtures(
|
||||
unittest.FixturesOptions{
|
||||
Dir: path.Join(curDir, "models/fixtures/"),
|
||||
},
|
||||
)
|
||||
@ -108,7 +109,7 @@ func runPR() {
|
||||
fmt.Printf("Error initializing test database: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
db.LoadFixtures()
|
||||
unittest.LoadFixtures()
|
||||
util.RemoveAll(setting.RepoRootPath)
|
||||
util.RemoveAll(models.LocalCopyPath())
|
||||
util.CopyDir(path.Join(curDir, "integrations/gitea-repositories-meta"), setting.RepoRootPath)
|
||||
|
@ -10,6 +10,8 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
@ -18,7 +20,7 @@ import (
|
||||
)
|
||||
|
||||
func TestAPIModifyLabels(t *testing.T) {
|
||||
assert.NoError(t, db.LoadFixtures())
|
||||
assert.NoError(t, unittest.LoadFixtures())
|
||||
|
||||
repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 2}).(*models.Repository)
|
||||
owner := db.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
|
||||
@ -88,7 +90,7 @@ func TestAPIModifyLabels(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAPIAddIssueLabels(t *testing.T) {
|
||||
assert.NoError(t, db.LoadFixtures())
|
||||
assert.NoError(t, unittest.LoadFixtures())
|
||||
|
||||
repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
|
||||
issue := db.AssertExistsAndLoadBean(t, &models.Issue{RepoID: repo.ID}).(*models.Issue)
|
||||
@ -111,7 +113,7 @@ func TestAPIAddIssueLabels(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAPIReplaceIssueLabels(t *testing.T) {
|
||||
assert.NoError(t, db.LoadFixtures())
|
||||
assert.NoError(t, unittest.LoadFixtures())
|
||||
|
||||
repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
|
||||
issue := db.AssertExistsAndLoadBean(t, &models.Issue{RepoID: repo.ID}).(*models.Issue)
|
||||
@ -137,7 +139,7 @@ func TestAPIReplaceIssueLabels(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAPIModifyOrgLabels(t *testing.T) {
|
||||
assert.NoError(t, db.LoadFixtures())
|
||||
assert.NoError(t, unittest.LoadFixtures())
|
||||
|
||||
repo := db.AssertExistsAndLoadBean(t, &models.Repository{ID: 3}).(*models.Repository)
|
||||
owner := db.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
|
||||
|
@ -25,7 +25,7 @@ import (
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
"code.gitea.io/gitea/modules/base"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/graceful"
|
||||
@ -84,6 +84,7 @@ func NewNilResponseHashSumRecorder() *NilResponseHashSumRecorder {
|
||||
func TestMain(m *testing.M) {
|
||||
defer log.Close()
|
||||
|
||||
unittest.InitUnitTestBridge()
|
||||
managerCtx, cancel := context.WithCancel(context.Background())
|
||||
graceful.InitManager(managerCtx)
|
||||
defer cancel()
|
||||
@ -112,8 +113,8 @@ func TestMain(m *testing.M) {
|
||||
}
|
||||
}
|
||||
|
||||
err := db.InitFixtures(
|
||||
db.FixturesOptions{
|
||||
err := unittest.InitFixtures(
|
||||
unittest.FixturesOptions{
|
||||
Dir: filepath.Join(filepath.Dir(setting.AppPath), "models/fixtures/"),
|
||||
},
|
||||
)
|
||||
@ -250,7 +251,7 @@ func prepareTestEnv(t testing.TB, skip ...int) func() {
|
||||
ourSkip += skip[0]
|
||||
}
|
||||
deferFn := PrintCurrentTest(t, ourSkip)
|
||||
assert.NoError(t, db.LoadFixtures())
|
||||
assert.NoError(t, unittest.LoadFixtures())
|
||||
assert.NoError(t, util.RemoveAll(setting.RepoRootPath))
|
||||
|
||||
assert.NoError(t, util.CopyDir(path.Join(filepath.Dir(setting.AppPath), "integrations/gitea-repositories-meta"), setting.RepoRootPath))
|
||||
@ -527,7 +528,7 @@ func GetCSRF(t testing.TB, session *TestSession, urlStr string) string {
|
||||
// within a single test this is required
|
||||
func resetFixtures(t *testing.T) {
|
||||
assert.NoError(t, queue.GetManager().FlushAll(context.Background(), -1))
|
||||
assert.NoError(t, db.LoadFixtures())
|
||||
assert.NoError(t, unittest.LoadFixtures())
|
||||
assert.NoError(t, util.RemoveAll(setting.RepoRootPath))
|
||||
assert.NoError(t, util.CopyDir(path.Join(filepath.Dir(setting.AppPath), "integrations/gitea-repositories-meta"), setting.RepoRootPath))
|
||||
}
|
||||
|
@ -8,6 +8,8 @@ import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/migrations"
|
||||
@ -17,7 +19,7 @@ import (
|
||||
)
|
||||
|
||||
func TestMigrateLocalPath(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
adminUser := db.AssertExistsAndLoadBean(t, &models.User{Name: "user1"}).(*models.User)
|
||||
|
||||
|
@ -8,8 +8,9 @@ import (
|
||||
"net/url"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/repofiles"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/test"
|
||||
@ -67,7 +68,7 @@ func TestDeleteRepoFile(t *testing.T) {
|
||||
|
||||
func testDeleteRepoFile(t *testing.T, u *url.URL) {
|
||||
// setup
|
||||
db.PrepareTestEnv(t)
|
||||
unittest.PrepareTestEnv(t)
|
||||
ctx := test.MockContext(t, "user2/repo1")
|
||||
ctx.SetParams(":id", "1")
|
||||
test.LoadRepo(t, ctx, 1)
|
||||
@ -106,7 +107,7 @@ func TestDeleteRepoFileWithoutBranchNames(t *testing.T) {
|
||||
|
||||
func testDeleteRepoFileWithoutBranchNames(t *testing.T, u *url.URL) {
|
||||
// setup
|
||||
db.PrepareTestEnv(t)
|
||||
unittest.PrepareTestEnv(t)
|
||||
ctx := test.MockContext(t, "user2/repo1")
|
||||
ctx.SetParams(":id", "1")
|
||||
test.LoadRepo(t, ctx, 1)
|
||||
@ -136,7 +137,7 @@ func testDeleteRepoFileWithoutBranchNames(t *testing.T, u *url.URL) {
|
||||
|
||||
func TestDeleteRepoFileErrors(t *testing.T) {
|
||||
// setup
|
||||
db.PrepareTestEnv(t)
|
||||
unittest.PrepareTestEnv(t)
|
||||
ctx := test.MockContext(t, "user2/repo1")
|
||||
ctx.SetParams(":id", "1")
|
||||
test.LoadRepo(t, ctx, 1)
|
||||
|
@ -8,11 +8,12 @@ import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestAccessLevel(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
user2 := db.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
|
||||
user5 := db.AssertExistsAndLoadBean(t, &User{ID: 5}).(*User)
|
||||
@ -63,7 +64,7 @@ func TestAccessLevel(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestHasAccess(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
user1 := db.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
|
||||
user2 := db.AssertExistsAndLoadBean(t, &User{ID: 5}).(*User)
|
||||
@ -89,7 +90,7 @@ func TestHasAccess(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUser_GetRepositoryAccesses(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
user1 := db.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
|
||||
accesses, err := user1.GetRepositoryAccesses()
|
||||
@ -103,7 +104,7 @@ func TestUser_GetRepositoryAccesses(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUser_GetAccessibleRepositories(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
user1 := db.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
|
||||
repos, err := user1.GetAccessibleRepositories(0)
|
||||
@ -123,7 +124,7 @@ func TestUser_GetAccessibleRepositories(t *testing.T) {
|
||||
|
||||
func TestRepository_RecalculateAccesses(t *testing.T) {
|
||||
// test with organization repo
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
repo1 := db.AssertExistsAndLoadBean(t, &Repository{ID: 3}).(*Repository)
|
||||
assert.NoError(t, repo1.GetOwner())
|
||||
|
||||
@ -140,7 +141,7 @@ func TestRepository_RecalculateAccesses(t *testing.T) {
|
||||
|
||||
func TestRepository_RecalculateAccesses2(t *testing.T) {
|
||||
// test with non-organization repo
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
repo1 := db.AssertExistsAndLoadBean(t, &Repository{ID: 4}).(*Repository)
|
||||
assert.NoError(t, repo1.GetOwner())
|
||||
|
||||
@ -154,7 +155,7 @@ func TestRepository_RecalculateAccesses2(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRepository_RecalculateAccesses3(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
team5 := db.AssertExistsAndLoadBean(t, &Team{ID: 5}).(*Team)
|
||||
user29 := db.AssertExistsAndLoadBean(t, &User{ID: 29}).(*User)
|
||||
|
||||
|
@ -9,13 +9,14 @@ import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestAction_GetRepoPath(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
repo := db.AssertExistsAndLoadBean(t, &Repository{}).(*Repository)
|
||||
owner := db.AssertExistsAndLoadBean(t, &User{ID: repo.OwnerID}).(*User)
|
||||
action := &Action{RepoID: repo.ID}
|
||||
@ -23,7 +24,7 @@ func TestAction_GetRepoPath(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAction_GetRepoLink(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
repo := db.AssertExistsAndLoadBean(t, &Repository{}).(*Repository)
|
||||
owner := db.AssertExistsAndLoadBean(t, &User{ID: repo.OwnerID}).(*User)
|
||||
action := &Action{RepoID: repo.ID}
|
||||
@ -34,7 +35,7 @@ func TestAction_GetRepoLink(t *testing.T) {
|
||||
|
||||
func TestGetFeeds(t *testing.T) {
|
||||
// test with an individual user
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
user := db.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
|
||||
|
||||
actions, err := GetFeeds(GetFeedsOptions{
|
||||
@ -62,7 +63,7 @@ func TestGetFeeds(t *testing.T) {
|
||||
|
||||
func TestGetFeeds2(t *testing.T) {
|
||||
// test with an organization user
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
org := db.AssertExistsAndLoadBean(t, &User{ID: 3}).(*User)
|
||||
user := db.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
|
||||
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@ -20,7 +21,7 @@ func TestNotice_TrStr(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCreateNotice(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
noticeBean := &Notice{
|
||||
Type: NoticeRepository,
|
||||
@ -32,7 +33,7 @@ func TestCreateNotice(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCreateRepositoryNotice(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
noticeBean := &Notice{
|
||||
Type: NoticeRepository,
|
||||
@ -46,12 +47,12 @@ func TestCreateRepositoryNotice(t *testing.T) {
|
||||
// TODO TestRemoveAllWithNotice
|
||||
|
||||
func TestCountNotices(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
assert.Equal(t, int64(3), CountNotices())
|
||||
}
|
||||
|
||||
func TestNotices(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
notices, err := Notices(1, 2)
|
||||
assert.NoError(t, err)
|
||||
@ -68,7 +69,7 @@ func TestNotices(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDeleteNotice(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
db.AssertExistsAndLoadBean(t, &Notice{ID: 3})
|
||||
assert.NoError(t, DeleteNotice(3))
|
||||
@ -77,7 +78,7 @@ func TestDeleteNotice(t *testing.T) {
|
||||
|
||||
func TestDeleteNotices(t *testing.T) {
|
||||
// delete a non-empty range
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
db.AssertExistsAndLoadBean(t, &Notice{ID: 1})
|
||||
db.AssertExistsAndLoadBean(t, &Notice{ID: 2})
|
||||
@ -90,7 +91,7 @@ func TestDeleteNotices(t *testing.T) {
|
||||
|
||||
func TestDeleteNotices2(t *testing.T) {
|
||||
// delete an empty range
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
db.AssertExistsAndLoadBean(t, &Notice{ID: 1})
|
||||
db.AssertExistsAndLoadBean(t, &Notice{ID: 2})
|
||||
@ -102,7 +103,7 @@ func TestDeleteNotices2(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDeleteNoticesByIDs(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
db.AssertExistsAndLoadBean(t, &Notice{ID: 1})
|
||||
db.AssertExistsAndLoadBean(t, &Notice{ID: 2})
|
||||
|
@ -9,11 +9,12 @@ import (
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/unit"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestIncreaseDownloadCount(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
attachment, err := GetAttachmentByUUID("a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11")
|
||||
assert.NoError(t, err)
|
||||
@ -29,7 +30,7 @@ func TestIncreaseDownloadCount(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetByCommentOrIssueID(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
// count of attachments from issue ID
|
||||
attachments, err := GetAttachmentsByIssueID(1)
|
||||
@ -42,7 +43,7 @@ func TestGetByCommentOrIssueID(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDeleteAttachments(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
count, err := DeleteAttachmentsByIssue(4, false)
|
||||
assert.NoError(t, err)
|
||||
@ -62,7 +63,7 @@ func TestDeleteAttachments(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetAttachmentByID(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
attach, err := GetAttachmentByID(1)
|
||||
assert.NoError(t, err)
|
||||
@ -78,7 +79,7 @@ func TestAttachment_DownloadURL(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUpdateAttachment(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
attach, err := GetAttachmentByID(1)
|
||||
assert.NoError(t, err)
|
||||
@ -91,7 +92,7 @@ func TestUpdateAttachment(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetAttachmentsByUUIDs(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
attachList, err := GetAttachmentsByUUIDs(db.DefaultContext, []string{"a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11", "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a17", "not-existing-uuid"})
|
||||
assert.NoError(t, err)
|
||||
@ -103,7 +104,7 @@ func TestGetAttachmentsByUUIDs(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLinkedRepository(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
testCases := []struct {
|
||||
name string
|
||||
attachID int64
|
||||
|
@ -8,11 +8,12 @@ import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestAddDeletedBranch(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
repo := db.AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
|
||||
firstBranch := db.AssertExistsAndLoadBean(t, &DeletedBranch{ID: 1}).(*DeletedBranch)
|
||||
|
||||
@ -21,7 +22,7 @@ func TestAddDeletedBranch(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetDeletedBranches(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
repo := db.AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
|
||||
|
||||
branches, err := repo.GetDeletedBranches()
|
||||
@ -30,14 +31,14 @@ func TestGetDeletedBranches(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetDeletedBranch(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
firstBranch := db.AssertExistsAndLoadBean(t, &DeletedBranch{ID: 1}).(*DeletedBranch)
|
||||
|
||||
assert.NotNil(t, getDeletedBranch(t, firstBranch))
|
||||
}
|
||||
|
||||
func TestDeletedBranchLoadUser(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
firstBranch := db.AssertExistsAndLoadBean(t, &DeletedBranch{ID: 1}).(*DeletedBranch)
|
||||
secondBranch := db.AssertExistsAndLoadBean(t, &DeletedBranch{ID: 2}).(*DeletedBranch)
|
||||
@ -56,7 +57,7 @@ func TestDeletedBranchLoadUser(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRemoveDeletedBranch(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
repo := db.AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
|
||||
|
||||
firstBranch := db.AssertExistsAndLoadBean(t, &DeletedBranch{ID: 1}).(*DeletedBranch)
|
||||
@ -81,7 +82,7 @@ func getDeletedBranch(t *testing.T, branch *DeletedBranch) *DeletedBranch {
|
||||
}
|
||||
|
||||
func TestFindRenamedBranch(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
branch, exist, err := FindRenamedBranch(1, "dev")
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, true, exist)
|
||||
@ -93,7 +94,7 @@ func TestFindRenamedBranch(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRenameBranch(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
repo1 := db.AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
|
||||
_isDefault := false
|
||||
|
||||
@ -130,7 +131,7 @@ func TestRenameBranch(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestOnlyGetDeletedBranchOnCorrectRepo(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
// Get deletedBranch with ID of 1 on repo with ID 2.
|
||||
// This should return a nil branch as this deleted branch
|
||||
|
@ -8,12 +8,13 @@ import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
"code.gitea.io/gitea/modules/structs"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestGetCommitStatuses(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
repo1 := db.AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
|
||||
|
||||
|
@ -7,29 +7,16 @@ package models
|
||||
import (
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/unittestbridge"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"xorm.io/builder"
|
||||
)
|
||||
|
||||
// CheckConsistencyForAll test that the entire database is consistent
|
||||
func CheckConsistencyForAll(t *testing.T) {
|
||||
CheckConsistencyFor(t,
|
||||
&User{},
|
||||
&Repository{},
|
||||
&Issue{},
|
||||
&PullRequest{},
|
||||
&Milestone{},
|
||||
&Label{},
|
||||
&Team{},
|
||||
&Action{})
|
||||
}
|
||||
|
||||
// CheckConsistencyFor test that all matching database entries are consistent
|
||||
func CheckConsistencyFor(t *testing.T, beansToCheck ...interface{}) {
|
||||
func CheckConsistencyFor(t unittestbridge.Tester, beansToCheck ...interface{}) {
|
||||
ta := unittestbridge.NewAsserter(t)
|
||||
for _, bean := range beansToCheck {
|
||||
sliceType := reflect.SliceOf(reflect.TypeOf(bean))
|
||||
sliceValue := reflect.MakeSlice(sliceType, 0, 10)
|
||||
@ -37,133 +24,133 @@ func CheckConsistencyFor(t *testing.T, beansToCheck ...interface{}) {
|
||||
ptrToSliceValue := reflect.New(sliceType)
|
||||
ptrToSliceValue.Elem().Set(sliceValue)
|
||||
|
||||
assert.NoError(t, db.GetEngine(db.DefaultContext).Table(bean).Find(ptrToSliceValue.Interface()))
|
||||
ta.NoError(db.GetEngine(db.DefaultContext).Table(bean).Find(ptrToSliceValue.Interface()))
|
||||
sliceValue = ptrToSliceValue.Elem()
|
||||
|
||||
for i := 0; i < sliceValue.Len(); i++ {
|
||||
entity := sliceValue.Index(i).Interface()
|
||||
checkForConsistency(entity, t)
|
||||
checkForConsistency(ta, entity)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func checkForConsistency(bean interface{}, t *testing.T) {
|
||||
func checkForConsistency(ta unittestbridge.Asserter, bean interface{}) {
|
||||
switch b := bean.(type) {
|
||||
case *User:
|
||||
checkForUserConsistency(b, t)
|
||||
checkForUserConsistency(b, ta)
|
||||
case *Repository:
|
||||
checkForRepoConsistency(b, t)
|
||||
checkForRepoConsistency(b, ta)
|
||||
case *Issue:
|
||||
checkForIssueConsistency(b, t)
|
||||
checkForIssueConsistency(b, ta)
|
||||
case *PullRequest:
|
||||
checkForPullRequestConsistency(b, t)
|
||||
checkForPullRequestConsistency(b, ta)
|
||||
case *Milestone:
|
||||
checkForMilestoneConsistency(b, t)
|
||||
checkForMilestoneConsistency(b, ta)
|
||||
case *Label:
|
||||
checkForLabelConsistency(b, t)
|
||||
checkForLabelConsistency(b, ta)
|
||||
case *Team:
|
||||
checkForTeamConsistency(b, t)
|
||||
checkForTeamConsistency(b, ta)
|
||||
case *Action:
|
||||
checkForActionConsistency(b, t)
|
||||
checkForActionConsistency(b, ta)
|
||||
default:
|
||||
t.Errorf("unknown bean type: %#v", bean)
|
||||
ta.Errorf("unknown bean type: %#v", bean)
|
||||
}
|
||||
}
|
||||
|
||||
// getCount get the count of database entries matching bean
|
||||
func getCount(t *testing.T, e db.Engine, bean interface{}) int64 {
|
||||
func getCount(ta unittestbridge.Asserter, e db.Engine, bean interface{}) int64 {
|
||||
count, err := e.Count(bean)
|
||||
assert.NoError(t, err)
|
||||
ta.NoError(err)
|
||||
return count
|
||||
}
|
||||
|
||||
// assertCount test the count of database entries matching bean
|
||||
func assertCount(t *testing.T, bean interface{}, expected int) {
|
||||
assert.EqualValues(t, expected, getCount(t, db.GetEngine(db.DefaultContext), bean),
|
||||
func assertCount(ta unittestbridge.Asserter, bean interface{}, expected int) {
|
||||
ta.EqualValues(expected, getCount(ta, db.GetEngine(db.DefaultContext), bean),
|
||||
"Failed consistency test, the counted bean (of type %T) was %+v", bean, bean)
|
||||
}
|
||||
|
||||
func checkForUserConsistency(user *User, t *testing.T) {
|
||||
assertCount(t, &Repository{OwnerID: user.ID}, user.NumRepos)
|
||||
assertCount(t, &Star{UID: user.ID}, user.NumStars)
|
||||
assertCount(t, &OrgUser{OrgID: user.ID}, user.NumMembers)
|
||||
assertCount(t, &Team{OrgID: user.ID}, user.NumTeams)
|
||||
assertCount(t, &Follow{UserID: user.ID}, user.NumFollowing)
|
||||
assertCount(t, &Follow{FollowID: user.ID}, user.NumFollowers)
|
||||
func checkForUserConsistency(user *User, ta unittestbridge.Asserter) {
|
||||
assertCount(ta, &Repository{OwnerID: user.ID}, user.NumRepos)
|
||||
assertCount(ta, &Star{UID: user.ID}, user.NumStars)
|
||||
assertCount(ta, &OrgUser{OrgID: user.ID}, user.NumMembers)
|
||||
assertCount(ta, &Team{OrgID: user.ID}, user.NumTeams)
|
||||
assertCount(ta, &Follow{UserID: user.ID}, user.NumFollowing)
|
||||
assertCount(ta, &Follow{FollowID: user.ID}, user.NumFollowers)
|
||||
if user.Type != UserTypeOrganization {
|
||||
assert.EqualValues(t, 0, user.NumMembers)
|
||||
assert.EqualValues(t, 0, user.NumTeams)
|
||||
ta.EqualValues(0, user.NumMembers)
|
||||
ta.EqualValues(0, user.NumTeams)
|
||||
}
|
||||
}
|
||||
|
||||
func checkForRepoConsistency(repo *Repository, t *testing.T) {
|
||||
assert.Equal(t, repo.LowerName, strings.ToLower(repo.Name), "repo: %+v", repo)
|
||||
assertCount(t, &Star{RepoID: repo.ID}, repo.NumStars)
|
||||
assertCount(t, &Milestone{RepoID: repo.ID}, repo.NumMilestones)
|
||||
assertCount(t, &Repository{ForkID: repo.ID}, repo.NumForks)
|
||||
func checkForRepoConsistency(repo *Repository, ta unittestbridge.Asserter) {
|
||||
ta.Equal(repo.LowerName, strings.ToLower(repo.Name), "repo: %+v", repo)
|
||||
assertCount(ta, &Star{RepoID: repo.ID}, repo.NumStars)
|
||||
assertCount(ta, &Milestone{RepoID: repo.ID}, repo.NumMilestones)
|
||||
assertCount(ta, &Repository{ForkID: repo.ID}, repo.NumForks)
|
||||
if repo.IsFork {
|
||||
db.AssertExistsAndLoadBean(t, &Repository{ID: repo.ForkID})
|
||||
db.AssertExistsAndLoadBean(ta, &Repository{ID: repo.ForkID})
|
||||
}
|
||||
|
||||
actual := getCount(t, db.GetEngine(db.DefaultContext).Where("Mode<>?", RepoWatchModeDont), &Watch{RepoID: repo.ID})
|
||||
assert.EqualValues(t, repo.NumWatches, actual,
|
||||
actual := getCount(ta, db.GetEngine(db.DefaultContext).Where("Mode<>?", RepoWatchModeDont), &Watch{RepoID: repo.ID})
|
||||
ta.EqualValues(repo.NumWatches, actual,
|
||||
"Unexpected number of watches for repo %+v", repo)
|
||||
|
||||
actual = getCount(t, db.GetEngine(db.DefaultContext).Where("is_pull=?", false), &Issue{RepoID: repo.ID})
|
||||
assert.EqualValues(t, repo.NumIssues, actual,
|
||||
actual = getCount(ta, db.GetEngine(db.DefaultContext).Where("is_pull=?", false), &Issue{RepoID: repo.ID})
|
||||
ta.EqualValues(repo.NumIssues, actual,
|
||||
"Unexpected number of issues for repo %+v", repo)
|
||||
|
||||
actual = getCount(t, db.GetEngine(db.DefaultContext).Where("is_pull=? AND is_closed=?", false, true), &Issue{RepoID: repo.ID})
|
||||
assert.EqualValues(t, repo.NumClosedIssues, actual,
|
||||
actual = getCount(ta, db.GetEngine(db.DefaultContext).Where("is_pull=? AND is_closed=?", false, true), &Issue{RepoID: repo.ID})
|
||||
ta.EqualValues(repo.NumClosedIssues, actual,
|
||||
"Unexpected number of closed issues for repo %+v", repo)
|
||||
|
||||
actual = getCount(t, db.GetEngine(db.DefaultContext).Where("is_pull=?", true), &Issue{RepoID: repo.ID})
|
||||
assert.EqualValues(t, repo.NumPulls, actual,
|
||||
actual = getCount(ta, db.GetEngine(db.DefaultContext).Where("is_pull=?", true), &Issue{RepoID: repo.ID})
|
||||
ta.EqualValues(repo.NumPulls, actual,
|
||||
"Unexpected number of pulls for repo %+v", repo)
|
||||
|
||||
actual = getCount(t, db.GetEngine(db.DefaultContext).Where("is_pull=? AND is_closed=?", true, true), &Issue{RepoID: repo.ID})
|
||||
assert.EqualValues(t, repo.NumClosedPulls, actual,
|
||||
actual = getCount(ta, db.GetEngine(db.DefaultContext).Where("is_pull=? AND is_closed=?", true, true), &Issue{RepoID: repo.ID})
|
||||
ta.EqualValues(repo.NumClosedPulls, actual,
|
||||
"Unexpected number of closed pulls for repo %+v", repo)
|
||||
|
||||
actual = getCount(t, db.GetEngine(db.DefaultContext).Where("is_closed=?", true), &Milestone{RepoID: repo.ID})
|
||||
assert.EqualValues(t, repo.NumClosedMilestones, actual,
|
||||
actual = getCount(ta, db.GetEngine(db.DefaultContext).Where("is_closed=?", true), &Milestone{RepoID: repo.ID})
|
||||
ta.EqualValues(repo.NumClosedMilestones, actual,
|
||||
"Unexpected number of closed milestones for repo %+v", repo)
|
||||
}
|
||||
|
||||
func checkForIssueConsistency(issue *Issue, t *testing.T) {
|
||||
actual := getCount(t, db.GetEngine(db.DefaultContext).Where("type=?", CommentTypeComment), &Comment{IssueID: issue.ID})
|
||||
assert.EqualValues(t, issue.NumComments, actual,
|
||||
func checkForIssueConsistency(issue *Issue, ta unittestbridge.Asserter) {
|
||||
actual := getCount(ta, db.GetEngine(db.DefaultContext).Where("type=?", CommentTypeComment), &Comment{IssueID: issue.ID})
|
||||
ta.EqualValues(issue.NumComments, actual,
|
||||
"Unexpected number of comments for issue %+v", issue)
|
||||
if issue.IsPull {
|
||||
pr := db.AssertExistsAndLoadBean(t, &PullRequest{IssueID: issue.ID}).(*PullRequest)
|
||||
assert.EqualValues(t, pr.Index, issue.Index)
|
||||
pr := db.AssertExistsAndLoadBean(ta, &PullRequest{IssueID: issue.ID}).(*PullRequest)
|
||||
ta.EqualValues(pr.Index, issue.Index)
|
||||
}
|
||||
}
|
||||
|
||||
func checkForPullRequestConsistency(pr *PullRequest, t *testing.T) {
|
||||
issue := db.AssertExistsAndLoadBean(t, &Issue{ID: pr.IssueID}).(*Issue)
|
||||
assert.True(t, issue.IsPull)
|
||||
assert.EqualValues(t, issue.Index, pr.Index)
|
||||
func checkForPullRequestConsistency(pr *PullRequest, ta unittestbridge.Asserter) {
|
||||
issue := db.AssertExistsAndLoadBean(ta, &Issue{ID: pr.IssueID}).(*Issue)
|
||||
ta.True(issue.IsPull)
|
||||
ta.EqualValues(issue.Index, pr.Index)
|
||||
}
|
||||
|
||||
func checkForMilestoneConsistency(milestone *Milestone, t *testing.T) {
|
||||
assertCount(t, &Issue{MilestoneID: milestone.ID}, milestone.NumIssues)
|
||||
func checkForMilestoneConsistency(milestone *Milestone, ta unittestbridge.Asserter) {
|
||||
assertCount(ta, &Issue{MilestoneID: milestone.ID}, milestone.NumIssues)
|
||||
|
||||
actual := getCount(t, db.GetEngine(db.DefaultContext).Where("is_closed=?", true), &Issue{MilestoneID: milestone.ID})
|
||||
assert.EqualValues(t, milestone.NumClosedIssues, actual,
|
||||
actual := getCount(ta, db.GetEngine(db.DefaultContext).Where("is_closed=?", true), &Issue{MilestoneID: milestone.ID})
|
||||
ta.EqualValues(milestone.NumClosedIssues, actual,
|
||||
"Unexpected number of closed issues for milestone %+v", milestone)
|
||||
|
||||
completeness := 0
|
||||
if milestone.NumIssues > 0 {
|
||||
completeness = milestone.NumClosedIssues * 100 / milestone.NumIssues
|
||||
}
|
||||
assert.Equal(t, completeness, milestone.Completeness)
|
||||
ta.Equal(completeness, milestone.Completeness)
|
||||
}
|
||||
|
||||
func checkForLabelConsistency(label *Label, t *testing.T) {
|
||||
func checkForLabelConsistency(label *Label, ta unittestbridge.Asserter) {
|
||||
issueLabels := make([]*IssueLabel, 0, 10)
|
||||
assert.NoError(t, db.GetEngine(db.DefaultContext).Find(&issueLabels, &IssueLabel{LabelID: label.ID}))
|
||||
assert.EqualValues(t, label.NumIssues, len(issueLabels),
|
||||
ta.NoError(db.GetEngine(db.DefaultContext).Find(&issueLabels, &IssueLabel{LabelID: label.ID}))
|
||||
ta.EqualValues(label.NumIssues, len(issueLabels),
|
||||
"Unexpected number of issue for label %+v", label)
|
||||
|
||||
issueIDs := make([]int64, len(issueLabels))
|
||||
@ -173,20 +160,20 @@ func checkForLabelConsistency(label *Label, t *testing.T) {
|
||||
|
||||
expected := int64(0)
|
||||
if len(issueIDs) > 0 {
|
||||
expected = getCount(t, db.GetEngine(db.DefaultContext).In("id", issueIDs).Where("is_closed=?", true), &Issue{})
|
||||
expected = getCount(ta, db.GetEngine(db.DefaultContext).In("id", issueIDs).Where("is_closed=?", true), &Issue{})
|
||||
}
|
||||
assert.EqualValues(t, expected, label.NumClosedIssues,
|
||||
ta.EqualValues(expected, label.NumClosedIssues,
|
||||
"Unexpected number of closed issues for label %+v", label)
|
||||
}
|
||||
|
||||
func checkForTeamConsistency(team *Team, t *testing.T) {
|
||||
assertCount(t, &TeamUser{TeamID: team.ID}, team.NumMembers)
|
||||
assertCount(t, &TeamRepo{TeamID: team.ID}, team.NumRepos)
|
||||
func checkForTeamConsistency(team *Team, ta unittestbridge.Asserter) {
|
||||
assertCount(ta, &TeamUser{TeamID: team.ID}, team.NumMembers)
|
||||
assertCount(ta, &TeamRepo{TeamID: team.ID}, team.NumRepos)
|
||||
}
|
||||
|
||||
func checkForActionConsistency(action *Action, t *testing.T) {
|
||||
repo := db.AssertExistsAndLoadBean(t, &Repository{ID: action.RepoID}).(*Repository)
|
||||
assert.Equal(t, repo.IsPrivate, action.IsPrivate, "action: %+v", action)
|
||||
func checkForActionConsistency(action *Action, ta unittestbridge.Asserter) {
|
||||
repo := db.AssertExistsAndLoadBean(ta, &Repository{ID: action.RepoID}).(*Repository)
|
||||
ta.Equal(repo.IsPrivate, action.IsPrivate, "action: %+v", action)
|
||||
}
|
||||
|
||||
// CountOrphanedLabels return count of labels witch are broken and not accessible via ui anymore
|
||||
|
@ -8,11 +8,12 @@ import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestDeleteOrphanedObjects(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
countBefore, err := db.GetEngine(db.DefaultContext).Count(&PullRequest{})
|
||||
assert.NoError(t, err)
|
||||
|
@ -124,7 +124,8 @@ func NewEngine() (*xorm.Engine, error) {
|
||||
return engine, nil
|
||||
}
|
||||
|
||||
func syncTables() error {
|
||||
//SyncAllTables sync the schemas of all tables, is required by unit test code
|
||||
func SyncAllTables() error {
|
||||
return x.StoreEngine("InnoDB").Sync2(tables...)
|
||||
}
|
||||
|
||||
@ -176,7 +177,7 @@ func InitEngineWithMigration(ctx context.Context, migrateFunc func(*xorm.Engine)
|
||||
return fmt.Errorf("migrate: %v", err)
|
||||
}
|
||||
|
||||
if err = syncTables(); err != nil {
|
||||
if err = SyncAllTables(); err != nil {
|
||||
return fmt.Errorf("sync database struct error: %v", err)
|
||||
}
|
||||
|
||||
|
@ -2,13 +2,15 @@
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package db
|
||||
package paginator
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
MainTest(m, filepath.Join("..", ".."))
|
||||
unittest.MainTest(m, filepath.Join("..", "..", ".."))
|
||||
}
|
8
models/db/paginator/paginator.go
Normal file
8
models/db/paginator/paginator.go
Normal file
@ -0,0 +1,8 @@
|
||||
// Copyright 2021 The Gitea Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package paginator
|
||||
|
||||
// dummy only. in the future, the models/db/list_options.go should be moved here to decouple from db package
|
||||
// otherwise the unit test will cause cycle import
|
@ -2,11 +2,12 @@
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package db
|
||||
package paginator
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@ -14,35 +15,35 @@ import (
|
||||
|
||||
func TestPaginator(t *testing.T) {
|
||||
cases := []struct {
|
||||
Paginator
|
||||
db.Paginator
|
||||
Skip int
|
||||
Take int
|
||||
Start int
|
||||
End int
|
||||
}{
|
||||
{
|
||||
Paginator: &ListOptions{Page: -1, PageSize: -1},
|
||||
Paginator: &db.ListOptions{Page: -1, PageSize: -1},
|
||||
Skip: 0,
|
||||
Take: setting.API.DefaultPagingNum,
|
||||
Start: 0,
|
||||
End: setting.API.DefaultPagingNum,
|
||||
},
|
||||
{
|
||||
Paginator: &ListOptions{Page: 2, PageSize: 10},
|
||||
Paginator: &db.ListOptions{Page: 2, PageSize: 10},
|
||||
Skip: 10,
|
||||
Take: 10,
|
||||
Start: 10,
|
||||
End: 20,
|
||||
},
|
||||
{
|
||||
Paginator: NewAbsoluteListOptions(-1, -1),
|
||||
Paginator: db.NewAbsoluteListOptions(-1, -1),
|
||||
Skip: 0,
|
||||
Take: setting.API.DefaultPagingNum,
|
||||
Start: 0,
|
||||
End: setting.API.DefaultPagingNum,
|
||||
},
|
||||
{
|
||||
Paginator: NewAbsoluteListOptions(2, 10),
|
||||
Paginator: db.NewAbsoluteListOptions(2, 10),
|
||||
Skip: 2,
|
||||
Take: 10,
|
||||
Start: 2,
|
@ -6,157 +6,26 @@ package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/modules/base"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/storage"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
"code.gitea.io/gitea/modules/unittestbridge"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"xorm.io/xorm"
|
||||
"xorm.io/xorm/names"
|
||||
)
|
||||
|
||||
// Code in this file is mainly used by models.CheckConsistencyFor, which is not in the unit test for various reasons.
|
||||
// In the future if we can decouple CheckConsistencyFor into separate unit test code, then this file can be moved into unittest package too.
|
||||
|
||||
// NonexistentID an ID that will never exist
|
||||
const NonexistentID = int64(math.MaxInt64)
|
||||
|
||||
// giteaRoot a path to the gitea root
|
||||
var (
|
||||
giteaRoot string
|
||||
fixturesDir string
|
||||
)
|
||||
|
||||
// FixturesDir returns the fixture directory
|
||||
func FixturesDir() string {
|
||||
return fixturesDir
|
||||
}
|
||||
|
||||
func fatalTestError(fmtStr string, args ...interface{}) {
|
||||
fmt.Fprintf(os.Stderr, fmtStr, args...)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// MainTest a reusable TestMain(..) function for unit tests that need to use a
|
||||
// test database. Creates the test database, and sets necessary settings.
|
||||
func MainTest(m *testing.M, pathToGiteaRoot string, fixtureFiles ...string) {
|
||||
var err error
|
||||
giteaRoot = pathToGiteaRoot
|
||||
fixturesDir = filepath.Join(pathToGiteaRoot, "models", "fixtures")
|
||||
|
||||
var opts FixturesOptions
|
||||
if len(fixtureFiles) == 0 {
|
||||
opts.Dir = fixturesDir
|
||||
} else {
|
||||
for _, f := range fixtureFiles {
|
||||
if len(f) != 0 {
|
||||
opts.Files = append(opts.Files, filepath.Join(fixturesDir, f))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if err = CreateTestEngine(opts); err != nil {
|
||||
fatalTestError("Error creating test engine: %v\n", err)
|
||||
}
|
||||
|
||||
setting.AppURL = "https://try.gitea.io/"
|
||||
setting.RunUser = "runuser"
|
||||
setting.SSH.Port = 3000
|
||||
setting.SSH.Domain = "try.gitea.io"
|
||||
setting.Database.UseSQLite3 = true
|
||||
setting.RepoRootPath, err = os.MkdirTemp(os.TempDir(), "repos")
|
||||
if err != nil {
|
||||
fatalTestError("TempDir: %v\n", err)
|
||||
}
|
||||
setting.AppDataPath, err = os.MkdirTemp(os.TempDir(), "appdata")
|
||||
if err != nil {
|
||||
fatalTestError("TempDir: %v\n", err)
|
||||
}
|
||||
setting.AppWorkPath = pathToGiteaRoot
|
||||
setting.StaticRootPath = pathToGiteaRoot
|
||||
setting.GravatarSourceURL, err = url.Parse("https://secure.gravatar.com/avatar/")
|
||||
if err != nil {
|
||||
fatalTestError("url.Parse: %v\n", err)
|
||||
}
|
||||
setting.Attachment.Storage.Path = filepath.Join(setting.AppDataPath, "attachments")
|
||||
|
||||
setting.LFS.Storage.Path = filepath.Join(setting.AppDataPath, "lfs")
|
||||
|
||||
setting.Avatar.Storage.Path = filepath.Join(setting.AppDataPath, "avatars")
|
||||
|
||||
setting.RepoAvatar.Storage.Path = filepath.Join(setting.AppDataPath, "repo-avatars")
|
||||
|
||||
setting.RepoArchive.Storage.Path = filepath.Join(setting.AppDataPath, "repo-archive")
|
||||
|
||||
if err = storage.Init(); err != nil {
|
||||
fatalTestError("storage.Init: %v\n", err)
|
||||
}
|
||||
|
||||
if err = util.RemoveAll(setting.RepoRootPath); err != nil {
|
||||
fatalTestError("util.RemoveAll: %v\n", err)
|
||||
}
|
||||
if err = util.CopyDir(filepath.Join(pathToGiteaRoot, "integrations", "gitea-repositories-meta"), setting.RepoRootPath); err != nil {
|
||||
fatalTestError("util.CopyDir: %v\n", err)
|
||||
}
|
||||
|
||||
exitStatus := m.Run()
|
||||
if err = util.RemoveAll(setting.RepoRootPath); err != nil {
|
||||
fatalTestError("util.RemoveAll: %v\n", err)
|
||||
}
|
||||
if err = util.RemoveAll(setting.AppDataPath); err != nil {
|
||||
fatalTestError("util.RemoveAll: %v\n", err)
|
||||
}
|
||||
os.Exit(exitStatus)
|
||||
}
|
||||
|
||||
// FixturesOptions fixtures needs to be loaded options
|
||||
type FixturesOptions struct {
|
||||
Dir string
|
||||
Files []string
|
||||
}
|
||||
|
||||
// CreateTestEngine creates a memory database and loads the fixture data from fixturesDir
|
||||
func CreateTestEngine(opts FixturesOptions) error {
|
||||
var err error
|
||||
x, err = xorm.NewEngine("sqlite3", "file::memory:?cache=shared&_txlock=immediate")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
x.SetMapper(names.GonicMapper{})
|
||||
if err = syncTables(); err != nil {
|
||||
return err
|
||||
}
|
||||
switch os.Getenv("GITEA_UNIT_TESTS_VERBOSE") {
|
||||
case "true", "1":
|
||||
x.ShowSQL(true)
|
||||
}
|
||||
|
||||
//SetUnitTestEngine is used by unit test code
|
||||
func SetUnitTestEngine(eng *xorm.Engine) {
|
||||
x = eng
|
||||
DefaultContext = &Context{
|
||||
Context: context.Background(),
|
||||
e: x,
|
||||
}
|
||||
|
||||
return InitFixtures(opts)
|
||||
}
|
||||
|
||||
// PrepareTestDatabase load test fixtures into test database
|
||||
func PrepareTestDatabase() error {
|
||||
return LoadFixtures()
|
||||
}
|
||||
|
||||
// PrepareTestEnv prepares the environment for unit tests. Can only be called
|
||||
// by tests that use the above MainTest(..) function.
|
||||
func PrepareTestEnv(t testing.TB) {
|
||||
assert.NoError(t, PrepareTestDatabase())
|
||||
assert.NoError(t, util.RemoveAll(setting.RepoRootPath))
|
||||
metaPath := filepath.Join(giteaRoot, "integrations", "gitea-repositories-meta")
|
||||
assert.NoError(t, util.CopyDir(metaPath, setting.RepoRootPath))
|
||||
base.SetupGiteaRoot() // Makes sure GITEA_ROOT is set
|
||||
}
|
||||
|
||||
type testCond struct {
|
||||
@ -182,10 +51,6 @@ func whereConditions(sess *xorm.Session, conditions []interface{}) {
|
||||
|
||||
// LoadBeanIfExists loads beans from fixture database if exist
|
||||
func LoadBeanIfExists(bean interface{}, conditions ...interface{}) (bool, error) {
|
||||
return loadBeanIfExists(bean, conditions...)
|
||||
}
|
||||
|
||||
func loadBeanIfExists(bean interface{}, conditions ...interface{}) (bool, error) {
|
||||
sess := x.NewSession()
|
||||
defer sess.Close()
|
||||
whereConditions(sess, conditions)
|
||||
@ -193,61 +58,68 @@ func loadBeanIfExists(bean interface{}, conditions ...interface{}) (bool, error)
|
||||
}
|
||||
|
||||
// BeanExists for testing, check if a bean exists
|
||||
func BeanExists(t testing.TB, bean interface{}, conditions ...interface{}) bool {
|
||||
exists, err := loadBeanIfExists(bean, conditions...)
|
||||
assert.NoError(t, err)
|
||||
func BeanExists(t unittestbridge.Tester, bean interface{}, conditions ...interface{}) bool {
|
||||
ta := unittestbridge.NewAsserter(t)
|
||||
exists, err := LoadBeanIfExists(bean, conditions...)
|
||||
ta.NoError(err)
|
||||
return exists
|
||||
}
|
||||
|
||||
// AssertExistsAndLoadBean assert that a bean exists and load it from the test
|
||||
// database
|
||||
func AssertExistsAndLoadBean(t testing.TB, bean interface{}, conditions ...interface{}) interface{} {
|
||||
exists, err := loadBeanIfExists(bean, conditions...)
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, exists,
|
||||
// AssertExistsAndLoadBean assert that a bean exists and load it from the test database
|
||||
func AssertExistsAndLoadBean(t unittestbridge.Tester, bean interface{}, conditions ...interface{}) interface{} {
|
||||
ta := unittestbridge.NewAsserter(t)
|
||||
exists, err := LoadBeanIfExists(bean, conditions...)
|
||||
ta.NoError(err)
|
||||
ta.True(exists,
|
||||
"Expected to find %+v (of type %T, with conditions %+v), but did not",
|
||||
bean, bean, conditions)
|
||||
return bean
|
||||
}
|
||||
|
||||
// GetCount get the count of a bean
|
||||
func GetCount(t testing.TB, bean interface{}, conditions ...interface{}) int {
|
||||
func GetCount(t unittestbridge.Tester, bean interface{}, conditions ...interface{}) int {
|
||||
ta := unittestbridge.NewAsserter(t)
|
||||
sess := x.NewSession()
|
||||
defer sess.Close()
|
||||
whereConditions(sess, conditions)
|
||||
count, err := sess.Count(bean)
|
||||
assert.NoError(t, err)
|
||||
ta.NoError(err)
|
||||
return int(count)
|
||||
}
|
||||
|
||||
// AssertNotExistsBean assert that a bean does not exist in the test database
|
||||
func AssertNotExistsBean(t testing.TB, bean interface{}, conditions ...interface{}) {
|
||||
exists, err := loadBeanIfExists(bean, conditions...)
|
||||
assert.NoError(t, err)
|
||||
assert.False(t, exists)
|
||||
func AssertNotExistsBean(t unittestbridge.Tester, bean interface{}, conditions ...interface{}) {
|
||||
ta := unittestbridge.NewAsserter(t)
|
||||
exists, err := LoadBeanIfExists(bean, conditions...)
|
||||
ta.NoError(err)
|
||||
ta.False(exists)
|
||||
}
|
||||
|
||||
// AssertExistsIf asserts that a bean exists or does not exist, depending on
|
||||
// what is expected.
|
||||
func AssertExistsIf(t *testing.T, expected bool, bean interface{}, conditions ...interface{}) {
|
||||
exists, err := loadBeanIfExists(bean, conditions...)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, expected, exists)
|
||||
func AssertExistsIf(t unittestbridge.Tester, expected bool, bean interface{}, conditions ...interface{}) {
|
||||
ta := unittestbridge.NewAsserter(t)
|
||||
exists, err := LoadBeanIfExists(bean, conditions...)
|
||||
ta.NoError(err)
|
||||
ta.Equal(expected, exists)
|
||||
}
|
||||
|
||||
// AssertSuccessfulInsert assert that beans is successfully inserted
|
||||
func AssertSuccessfulInsert(t testing.TB, beans ...interface{}) {
|
||||
func AssertSuccessfulInsert(t unittestbridge.Tester, beans ...interface{}) {
|
||||
ta := unittestbridge.NewAsserter(t)
|
||||
_, err := x.Insert(beans...)
|
||||
assert.NoError(t, err)
|
||||
ta.NoError(err)
|
||||
}
|
||||
|
||||
// AssertCount assert the count of a bean
|
||||
func AssertCount(t testing.TB, bean, expected interface{}) {
|
||||
assert.EqualValues(t, expected, GetCount(t, bean))
|
||||
func AssertCount(t unittestbridge.Tester, bean, expected interface{}) {
|
||||
ta := unittestbridge.NewAsserter(t)
|
||||
ta.EqualValues(expected, GetCount(ta, bean))
|
||||
}
|
||||
|
||||
// AssertInt64InRange assert value is in range [low, high]
|
||||
func AssertInt64InRange(t testing.TB, low, high, value int64) {
|
||||
assert.True(t, value >= low && value <= high,
|
||||
func AssertInt64InRange(t unittestbridge.Tester, low, high, value int64) {
|
||||
ta := unittestbridge.NewAsserter(t)
|
||||
ta.True(value >= low && value <= high,
|
||||
"Expected value in range [%d, %d], found %d", low, high, value)
|
||||
}
|
||||
|
@ -10,13 +10,14 @@ import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestDumpDatabase(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
dir, err := os.MkdirTemp(os.TempDir(), "dump")
|
||||
assert.NoError(t, err)
|
||||
|
@ -9,21 +9,21 @@ import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestFixtureGeneration(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
test := func(gen func() (string, error), name string) {
|
||||
expected, err := gen()
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
bytes, err := os.ReadFile(filepath.Join(db.FixturesDir(), name+".yml"))
|
||||
bytes, err := os.ReadFile(filepath.Join(unittest.FixturesDir(), name+".yml"))
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@ -193,7 +194,7 @@ Unknown GPG key with good email
|
||||
}
|
||||
|
||||
func TestCheckGPGUserEmail(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
_ = db.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
|
||||
|
||||
|
@ -8,11 +8,12 @@ import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestUpdateAssignee(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
// Fake issue with assignees
|
||||
issue, err := GetIssueWithAttrsByID(1)
|
||||
@ -62,7 +63,7 @@ func TestUpdateAssignee(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMakeIDsFromAPIAssigneesToAdd(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
_ = db.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
|
||||
_ = db.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
|
||||
|
@ -9,11 +9,12 @@ import (
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestCreateComment(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
issue := db.AssertExistsAndLoadBean(t, &Issue{}).(*Issue)
|
||||
repo := db.AssertExistsAndLoadBean(t, &Repository{ID: issue.RepoID}).(*Repository)
|
||||
@ -42,7 +43,7 @@ func TestCreateComment(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestFetchCodeComments(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
issue := db.AssertExistsAndLoadBean(t, &Issue{ID: 2}).(*Issue)
|
||||
user := db.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
|
||||
|
@ -8,12 +8,13 @@ import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestCreateIssueDependency(t *testing.T) {
|
||||
// Prepare
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
user1, err := GetUserByID(1)
|
||||
assert.NoError(t, err)
|
||||
|
@ -9,20 +9,21 @@ import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
// TODO TestGetLabelTemplateFile
|
||||
|
||||
func TestLabel_CalOpenIssues(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
label := db.AssertExistsAndLoadBean(t, &Label{ID: 1}).(*Label)
|
||||
label.CalOpenIssues()
|
||||
assert.EqualValues(t, 2, label.NumOpenIssues)
|
||||
}
|
||||
|
||||
func TestLabel_ForegroundColor(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
label := db.AssertExistsAndLoadBean(t, &Label{ID: 1}).(*Label)
|
||||
assert.Equal(t, template.CSS("#000"), label.ForegroundColor())
|
||||
|
||||
@ -31,7 +32,7 @@ func TestLabel_ForegroundColor(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNewLabels(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
labels := []*Label{
|
||||
{RepoID: 2, Name: "labelName2", Color: "#123456"},
|
||||
{RepoID: 3, Name: "labelName3", Color: "#23456F"},
|
||||
@ -50,7 +51,7 @@ func TestNewLabels(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetLabelByID(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
label, err := GetLabelByID(1)
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 1, label.ID)
|
||||
@ -60,7 +61,7 @@ func TestGetLabelByID(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetLabelInRepoByName(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
label, err := GetLabelInRepoByName(1, "label1")
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 1, label.ID)
|
||||
@ -74,7 +75,7 @@ func TestGetLabelInRepoByName(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetLabelInRepoByNames(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
labelIDs, err := GetLabelIDsInRepoByNames(1, []string{"label1", "label2"})
|
||||
assert.NoError(t, err)
|
||||
|
||||
@ -85,7 +86,7 @@ func TestGetLabelInRepoByNames(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetLabelInRepoByNamesDiscardsNonExistentLabels(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
// label3 doesn't exists.. See labels.yml
|
||||
labelIDs, err := GetLabelIDsInRepoByNames(1, []string{"label1", "label2", "label3"})
|
||||
assert.NoError(t, err)
|
||||
@ -98,7 +99,7 @@ func TestGetLabelInRepoByNamesDiscardsNonExistentLabels(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetLabelInRepoByID(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
label, err := GetLabelInRepoByID(1, 1)
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 1, label.ID)
|
||||
@ -111,7 +112,7 @@ func TestGetLabelInRepoByID(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetLabelsInRepoByIDs(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
labels, err := GetLabelsInRepoByIDs(1, []int64{1, 2, db.NonexistentID})
|
||||
assert.NoError(t, err)
|
||||
if assert.Len(t, labels, 2) {
|
||||
@ -121,7 +122,7 @@ func TestGetLabelsInRepoByIDs(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetLabelsByRepoID(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
testSuccess := func(repoID int64, sortType string, expectedIssueIDs []int64) {
|
||||
labels, err := GetLabelsByRepoID(repoID, sortType, db.ListOptions{})
|
||||
assert.NoError(t, err)
|
||||
@ -139,7 +140,7 @@ func TestGetLabelsByRepoID(t *testing.T) {
|
||||
// Org versions
|
||||
|
||||
func TestGetLabelInOrgByName(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
label, err := GetLabelInOrgByName(3, "orglabel3")
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 3, label.ID)
|
||||
@ -159,7 +160,7 @@ func TestGetLabelInOrgByName(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetLabelInOrgByNames(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
labelIDs, err := GetLabelIDsInOrgByNames(3, []string{"orglabel3", "orglabel4"})
|
||||
assert.NoError(t, err)
|
||||
|
||||
@ -170,7 +171,7 @@ func TestGetLabelInOrgByNames(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetLabelInOrgByNamesDiscardsNonExistentLabels(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
// orglabel99 doesn't exists.. See labels.yml
|
||||
labelIDs, err := GetLabelIDsInOrgByNames(3, []string{"orglabel3", "orglabel4", "orglabel99"})
|
||||
assert.NoError(t, err)
|
||||
@ -183,7 +184,7 @@ func TestGetLabelInOrgByNamesDiscardsNonExistentLabels(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetLabelInOrgByID(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
label, err := GetLabelInOrgByID(3, 3)
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, 3, label.ID)
|
||||
@ -202,7 +203,7 @@ func TestGetLabelInOrgByID(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetLabelsInOrgByIDs(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
labels, err := GetLabelsInOrgByIDs(3, []int64{3, 4, db.NonexistentID})
|
||||
assert.NoError(t, err)
|
||||
if assert.Len(t, labels, 2) {
|
||||
@ -212,7 +213,7 @@ func TestGetLabelsInOrgByIDs(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetLabelsByOrgID(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
testSuccess := func(orgID int64, sortType string, expectedIssueIDs []int64) {
|
||||
labels, err := GetLabelsByOrgID(orgID, sortType, db.ListOptions{})
|
||||
assert.NoError(t, err)
|
||||
@ -237,7 +238,7 @@ func TestGetLabelsByOrgID(t *testing.T) {
|
||||
//
|
||||
|
||||
func TestGetLabelsByIssueID(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
labels, err := GetLabelsByIssueID(1)
|
||||
assert.NoError(t, err)
|
||||
if assert.Len(t, labels, 1) {
|
||||
@ -250,7 +251,7 @@ func TestGetLabelsByIssueID(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUpdateLabel(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
label := db.AssertExistsAndLoadBean(t, &Label{ID: 1}).(*Label)
|
||||
// make sure update wont overwrite it
|
||||
update := &Label{
|
||||
@ -271,7 +272,7 @@ func TestUpdateLabel(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDeleteLabel(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
label := db.AssertExistsAndLoadBean(t, &Label{ID: 1}).(*Label)
|
||||
assert.NoError(t, DeleteLabel(label.RepoID, label.ID))
|
||||
db.AssertNotExistsBean(t, &Label{ID: label.ID, RepoID: label.RepoID})
|
||||
@ -284,14 +285,14 @@ func TestDeleteLabel(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestHasIssueLabel(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
assert.True(t, HasIssueLabel(1, 1))
|
||||
assert.False(t, HasIssueLabel(1, 2))
|
||||
assert.False(t, HasIssueLabel(db.NonexistentID, db.NonexistentID))
|
||||
}
|
||||
|
||||
func TestNewIssueLabel(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
label := db.AssertExistsAndLoadBean(t, &Label{ID: 2}).(*Label)
|
||||
issue := db.AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue)
|
||||
doer := db.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
|
||||
@ -316,7 +317,7 @@ func TestNewIssueLabel(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNewIssueLabels(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
label1 := db.AssertExistsAndLoadBean(t, &Label{ID: 1}).(*Label)
|
||||
label2 := db.AssertExistsAndLoadBean(t, &Label{ID: 2}).(*Label)
|
||||
issue := db.AssertExistsAndLoadBean(t, &Issue{ID: 5}).(*Issue)
|
||||
@ -346,7 +347,7 @@ func TestNewIssueLabels(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDeleteIssueLabel(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
testSuccess := func(labelID, issueID, doerID int64) {
|
||||
label := db.AssertExistsAndLoadBean(t, &Label{ID: labelID}).(*Label)
|
||||
issue := db.AssertExistsAndLoadBean(t, &Issue{ID: issueID}).(*Issue)
|
||||
|
@ -8,13 +8,14 @@ import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestIssueList_LoadRepositories(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
issueList := IssueList{
|
||||
db.AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue),
|
||||
@ -31,7 +32,7 @@ func TestIssueList_LoadRepositories(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestIssueList_LoadAttributes(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
setting.Service.EnableTimetracking = true
|
||||
issueList := IssueList{
|
||||
db.AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue),
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
@ -23,7 +24,7 @@ func TestMilestone_State(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNewMilestone(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
milestone := &Milestone{
|
||||
RepoID: 1,
|
||||
Name: "milestoneName",
|
||||
@ -36,7 +37,7 @@ func TestNewMilestone(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetMilestoneByRepoID(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
milestone, err := GetMilestoneByRepoID(1, 1)
|
||||
assert.NoError(t, err)
|
||||
@ -48,7 +49,7 @@ func TestGetMilestoneByRepoID(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetMilestonesByRepoID(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
test := func(repoID int64, state api.StateType) {
|
||||
repo := db.AssertExistsAndLoadBean(t, &Repository{ID: repoID}).(*Repository)
|
||||
milestones, _, err := GetMilestones(GetMilestonesOption{
|
||||
@ -97,7 +98,7 @@ func TestGetMilestonesByRepoID(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetMilestones(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
repo := db.AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
|
||||
test := func(sortType string, sortCond func(*Milestone) int) {
|
||||
for _, page := range []int{0, 1} {
|
||||
@ -158,7 +159,7 @@ func TestGetMilestones(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUpdateMilestone(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
milestone := db.AssertExistsAndLoadBean(t, &Milestone{ID: 1}).(*Milestone)
|
||||
milestone.Name = " newMilestoneName "
|
||||
@ -170,7 +171,7 @@ func TestUpdateMilestone(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCountRepoMilestones(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
test := func(repoID int64) {
|
||||
repo := db.AssertExistsAndLoadBean(t, &Repository{ID: repoID}).(*Repository)
|
||||
count, err := countRepoMilestones(db.GetEngine(db.DefaultContext), repoID)
|
||||
@ -187,7 +188,7 @@ func TestCountRepoMilestones(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCountRepoClosedMilestones(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
test := func(repoID int64) {
|
||||
repo := db.AssertExistsAndLoadBean(t, &Repository{ID: repoID}).(*Repository)
|
||||
count, err := CountRepoClosedMilestones(repoID)
|
||||
@ -204,7 +205,7 @@ func TestCountRepoClosedMilestones(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestChangeMilestoneStatus(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
milestone := db.AssertExistsAndLoadBean(t, &Milestone{ID: 1}).(*Milestone)
|
||||
|
||||
assert.NoError(t, ChangeMilestoneStatus(milestone, true))
|
||||
@ -217,7 +218,7 @@ func TestChangeMilestoneStatus(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUpdateMilestoneCounters(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
issue := db.AssertExistsAndLoadBean(t, &Issue{MilestoneID: 1},
|
||||
"is_closed=0").(*Issue)
|
||||
|
||||
@ -237,7 +238,7 @@ func TestUpdateMilestoneCounters(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestChangeMilestoneAssign(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
issue := db.AssertExistsAndLoadBean(t, &Issue{RepoID: 1}).(*Issue)
|
||||
doer := db.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
|
||||
assert.NotNil(t, issue)
|
||||
@ -256,7 +257,7 @@ func TestChangeMilestoneAssign(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDeleteMilestoneByRepoID(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
assert.NoError(t, DeleteMilestoneByRepoID(1, 1))
|
||||
db.AssertNotExistsBean(t, &Milestone{ID: 1})
|
||||
CheckConsistencyFor(t, &Repository{ID: 1})
|
||||
@ -265,7 +266,7 @@ func TestDeleteMilestoneByRepoID(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMilestoneList_LoadTotalTrackedTimes(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
miles := MilestoneList{
|
||||
db.AssertExistsAndLoadBean(t, &Milestone{ID: 1}).(*Milestone),
|
||||
}
|
||||
@ -276,7 +277,7 @@ func TestMilestoneList_LoadTotalTrackedTimes(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCountMilestonesByRepoIDs(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
milestonesCount := func(repoID int64) (int, int) {
|
||||
repo := db.AssertExistsAndLoadBean(t, &Repository{ID: repoID}).(*Repository)
|
||||
return repo.NumOpenMilestones, repo.NumClosedMilestones
|
||||
@ -296,7 +297,7 @@ func TestCountMilestonesByRepoIDs(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetMilestonesByRepoIDs(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
repo1 := db.AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
|
||||
repo2 := db.AssertExistsAndLoadBean(t, &Repository{ID: 2}).(*Repository)
|
||||
test := func(sortType string, sortCond func(*Milestone) int) {
|
||||
@ -341,7 +342,7 @@ func TestGetMilestonesByRepoIDs(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLoadTotalTrackedTime(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
milestone := db.AssertExistsAndLoadBean(t, &Milestone{ID: 1}).(*Milestone)
|
||||
|
||||
assert.NoError(t, milestone.LoadTotalTrackedTime())
|
||||
@ -350,7 +351,7 @@ func TestLoadTotalTrackedTime(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetMilestonesStats(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
test := func(repoID int64) {
|
||||
repo := db.AssertExistsAndLoadBean(t, &Repository{ID: repoID}).(*Repository)
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@ -25,7 +26,7 @@ func addReaction(t *testing.T, doer *User, issue *Issue, comment *Comment, conte
|
||||
}
|
||||
|
||||
func TestIssueAddReaction(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
user1 := db.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
|
||||
|
||||
@ -37,7 +38,7 @@ func TestIssueAddReaction(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestIssueAddDuplicateReaction(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
user1 := db.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
|
||||
|
||||
@ -58,7 +59,7 @@ func TestIssueAddDuplicateReaction(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestIssueDeleteReaction(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
user1 := db.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
|
||||
|
||||
@ -73,7 +74,7 @@ func TestIssueDeleteReaction(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestIssueReactionCount(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
setting.UI.ReactionMaxUserNum = 2
|
||||
|
||||
@ -111,7 +112,7 @@ func TestIssueReactionCount(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestIssueCommentAddReaction(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
user1 := db.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
|
||||
|
||||
@ -125,7 +126,7 @@ func TestIssueCommentAddReaction(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestIssueCommentDeleteReaction(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
user1 := db.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
|
||||
user2 := db.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
|
||||
@ -152,7 +153,7 @@ func TestIssueCommentDeleteReaction(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestIssueCommentReactionCount(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
user1 := db.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
|
||||
|
||||
|
@ -8,13 +8,14 @@ import (
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/db"
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
"code.gitea.io/gitea/modules/timeutil"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestCancelStopwatch(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
user1, err := GetUserByID(1)
|
||||
assert.NoError(t, err)
|
||||
@ -34,14 +35,14 @@ func TestCancelStopwatch(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestStopwatchExists(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
assert.True(t, StopwatchExists(1, 1))
|
||||
assert.False(t, StopwatchExists(1, 2))
|
||||
}
|
||||
|
||||
func TestHasUserStopwatch(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
exists, sw, err := HasUserStopwatch(1)
|
||||
assert.NoError(t, err)
|
||||
@ -54,7 +55,7 @@ func TestHasUserStopwatch(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCreateOrStopIssueStopwatch(t *testing.T) {
|
||||
assert.NoError(t, db.PrepareTestDatabase())
|
||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||
|
||||
user2, err := GetUserByID(2)
|
||||
assert.NoError(t, err)
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user