aboutsummaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2021-11-16 16:53:21 +0800
committerGitHub <noreply@github.com>2021-11-16 16:53:21 +0800
commit81926d61db3dac223a75ea49eab893b25a089587 (patch)
tree627d2f19a008089f3a688e9a94a2cc8d2017afe2 /routers
parent23bd7b1211a80aa3b0dcb60ec4a1c0089ff28dd4 (diff)
downloadgitea-81926d61db3dac223a75ea49eab893b25a089587.tar.gz
gitea-81926d61db3dac223a75ea49eab893b25a089587.zip
Decouple unit test, remove intermediate `unittestbridge` package (#17662)
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Diffstat (limited to 'routers')
-rw-r--r--routers/api/v1/repo/hook_test.go5
-rw-r--r--routers/api/v1/repo/repo_test.go9
-rw-r--r--routers/web/admin/users_test.go11
-rw-r--r--routers/web/repo/issue_label_test.go21
-rw-r--r--routers/web/repo/release_test.go5
-rw-r--r--routers/web/repo/settings_test.go5
-rw-r--r--routers/web/user/oauth_test.go3
7 files changed, 26 insertions, 33 deletions
diff --git a/routers/api/v1/repo/hook_test.go b/routers/api/v1/repo/hook_test.go
index ff0aaf2938..07f1532f82 100644
--- a/routers/api/v1/repo/hook_test.go
+++ b/routers/api/v1/repo/hook_test.go
@@ -8,7 +8,6 @@ import (
"net/http"
"testing"
- "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/models/webhook"
"code.gitea.io/gitea/modules/context"
@@ -28,8 +27,8 @@ func TestTestHook(t *testing.T) {
TestHook(&context.APIContext{Context: ctx, Org: nil})
assert.EqualValues(t, http.StatusNoContent, ctx.Resp.Status())
- db.AssertExistsAndLoadBean(t, &webhook.HookTask{
+ unittest.AssertExistsAndLoadBean(t, &webhook.HookTask{
RepoID: 1,
HookID: 1,
- }, db.Cond("is_delivered=?", false))
+ }, unittest.Cond("is_delivered=?", false))
}
diff --git a/routers/api/v1/repo/repo_test.go b/routers/api/v1/repo/repo_test.go
index b992b93fd4..4d4093582b 100644
--- a/routers/api/v1/repo/repo_test.go
+++ b/routers/api/v1/repo/repo_test.go
@@ -9,7 +9,6 @@ import (
"testing"
"code.gitea.io/gitea/models"
- "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/context"
api "code.gitea.io/gitea/modules/structs"
@@ -61,9 +60,9 @@ func TestRepoEdit(t *testing.T) {
Edit(apiCtx)
assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
- db.AssertExistsAndLoadBean(t, &models.Repository{
+ unittest.AssertExistsAndLoadBean(t, &models.Repository{
ID: 1,
- }, db.Cond("name = ? AND is_archived = 1", *opts.Name))
+ }, unittest.Cond("name = ? AND is_archived = 1", *opts.Name))
}
func TestRepoEditNameChange(t *testing.T) {
@@ -83,7 +82,7 @@ func TestRepoEditNameChange(t *testing.T) {
Edit(apiCtx)
assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
- db.AssertExistsAndLoadBean(t, &models.Repository{
+ unittest.AssertExistsAndLoadBean(t, &models.Repository{
ID: 1,
- }, db.Cond("name = ?", opts.Name))
+ }, unittest.Cond("name = ?", opts.Name))
}
diff --git a/routers/web/admin/users_test.go b/routers/web/admin/users_test.go
index 62b35ea286..607ef2ea66 100644
--- a/routers/web/admin/users_test.go
+++ b/routers/web/admin/users_test.go
@@ -8,7 +8,6 @@ import (
"testing"
"code.gitea.io/gitea/models"
- "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"
@@ -24,7 +23,7 @@ func TestNewUserPost_MustChangePassword(t *testing.T) {
unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "admin/users/new")
- u := db.AssertExistsAndLoadBean(t, &models.User{
+ u := unittest.AssertExistsAndLoadBean(t, &models.User{
IsAdmin: true,
ID: 2,
}).(*models.User)
@@ -61,7 +60,7 @@ func TestNewUserPost_MustChangePasswordFalse(t *testing.T) {
unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "admin/users/new")
- u := db.AssertExistsAndLoadBean(t, &models.User{
+ u := unittest.AssertExistsAndLoadBean(t, &models.User{
IsAdmin: true,
ID: 2,
}).(*models.User)
@@ -98,7 +97,7 @@ func TestNewUserPost_InvalidEmail(t *testing.T) {
unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "admin/users/new")
- u := db.AssertExistsAndLoadBean(t, &models.User{
+ u := unittest.AssertExistsAndLoadBean(t, &models.User{
IsAdmin: true,
ID: 2,
}).(*models.User)
@@ -128,7 +127,7 @@ func TestNewUserPost_VisibilityDefaultPublic(t *testing.T) {
unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "admin/users/new")
- u := db.AssertExistsAndLoadBean(t, &models.User{
+ u := unittest.AssertExistsAndLoadBean(t, &models.User{
IsAdmin: true,
ID: 2,
}).(*models.User)
@@ -166,7 +165,7 @@ func TestNewUserPost_VisibilityPrivate(t *testing.T) {
unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "admin/users/new")
- u := db.AssertExistsAndLoadBean(t, &models.User{
+ u := unittest.AssertExistsAndLoadBean(t, &models.User{
IsAdmin: true,
ID: 2,
}).(*models.User)
diff --git a/routers/web/repo/issue_label_test.go b/routers/web/repo/issue_label_test.go
index 98fa9eb968..baa34530fa 100644
--- a/routers/web/repo/issue_label_test.go
+++ b/routers/web/repo/issue_label_test.go
@@ -10,7 +10,6 @@ import (
"testing"
"code.gitea.io/gitea/models"
- "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/test"
"code.gitea.io/gitea/modules/web"
@@ -38,7 +37,7 @@ func TestInitializeLabels(t *testing.T) {
web.SetForm(ctx, &forms.InitializeLabelsForm{TemplateName: "Default"})
InitializeLabels(ctx)
assert.EqualValues(t, http.StatusFound, ctx.Resp.Status())
- db.AssertExistsAndLoadBean(t, &models.Label{
+ unittest.AssertExistsAndLoadBean(t, &models.Label{
RepoID: 2,
Name: "enhancement",
Color: "#84b6eb",
@@ -84,7 +83,7 @@ func TestNewLabel(t *testing.T) {
})
NewLabel(ctx)
assert.EqualValues(t, http.StatusFound, ctx.Resp.Status())
- db.AssertExistsAndLoadBean(t, &models.Label{
+ unittest.AssertExistsAndLoadBean(t, &models.Label{
Name: "newlabel",
Color: "#abcdef",
})
@@ -103,7 +102,7 @@ func TestUpdateLabel(t *testing.T) {
})
UpdateLabel(ctx)
assert.EqualValues(t, http.StatusFound, ctx.Resp.Status())
- db.AssertExistsAndLoadBean(t, &models.Label{
+ unittest.AssertExistsAndLoadBean(t, &models.Label{
ID: 2,
Name: "newnameforlabel",
Color: "#abcdef",
@@ -119,8 +118,8 @@ func TestDeleteLabel(t *testing.T) {
ctx.Req.Form.Set("id", "2")
DeleteLabel(ctx)
assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
- db.AssertNotExistsBean(t, &models.Label{ID: 2})
- db.AssertNotExistsBean(t, &models.IssueLabel{LabelID: 2})
+ unittest.AssertNotExistsBean(t, &models.Label{ID: 2})
+ unittest.AssertNotExistsBean(t, &models.IssueLabel{LabelID: 2})
assert.Equal(t, ctx.Tr("repo.issues.label_deletion_success"), ctx.Flash.SuccessMsg)
}
@@ -133,9 +132,9 @@ func TestUpdateIssueLabel_Clear(t *testing.T) {
ctx.Req.Form.Set("action", "clear")
UpdateIssueLabel(ctx)
assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
- db.AssertNotExistsBean(t, &models.IssueLabel{IssueID: 1})
- db.AssertNotExistsBean(t, &models.IssueLabel{IssueID: 3})
- models.CheckConsistencyFor(t, &models.Label{})
+ unittest.AssertNotExistsBean(t, &models.IssueLabel{IssueID: 1})
+ unittest.AssertNotExistsBean(t, &models.IssueLabel{IssueID: 3})
+ unittest.CheckConsistencyFor(t, &models.Label{})
}
func TestUpdateIssueLabel_Toggle(t *testing.T) {
@@ -160,11 +159,11 @@ func TestUpdateIssueLabel_Toggle(t *testing.T) {
UpdateIssueLabel(ctx)
assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
for _, issueID := range testCase.IssueIDs {
- db.AssertExistsIf(t, testCase.ExpectedAdd, &models.IssueLabel{
+ unittest.AssertExistsIf(t, testCase.ExpectedAdd, &models.IssueLabel{
IssueID: issueID,
LabelID: testCase.LabelID,
})
}
- models.CheckConsistencyFor(t, &models.Label{})
+ unittest.CheckConsistencyFor(t, &models.Label{})
}
}
diff --git a/routers/web/repo/release_test.go b/routers/web/repo/release_test.go
index ff54232da7..33cf54cdc9 100644
--- a/routers/web/repo/release_test.go
+++ b/routers/web/repo/release_test.go
@@ -8,7 +8,6 @@ import (
"testing"
"code.gitea.io/gitea/models"
- "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/test"
"code.gitea.io/gitea/modules/web"
@@ -53,14 +52,14 @@ func TestNewReleasePost(t *testing.T) {
test.LoadGitRepo(t, ctx)
web.SetForm(ctx, &testCase.Form)
NewReleasePost(ctx)
- db.AssertExistsAndLoadBean(t, &models.Release{
+ unittest.AssertExistsAndLoadBean(t, &models.Release{
RepoID: 1,
PublisherID: 2,
TagName: testCase.Form.TagName,
Target: testCase.Form.Target,
Title: testCase.Form.Title,
Note: testCase.Form.Content,
- }, db.Cond("is_draft=?", len(testCase.Form.Draft) > 0))
+ }, unittest.Cond("is_draft=?", len(testCase.Form.Draft) > 0))
ctx.Repo.GitRepo.Close()
}
}
diff --git a/routers/web/repo/settings_test.go b/routers/web/repo/settings_test.go
index 78426f5b79..3e8ae2b07e 100644
--- a/routers/web/repo/settings_test.go
+++ b/routers/web/repo/settings_test.go
@@ -10,7 +10,6 @@ import (
"testing"
"code.gitea.io/gitea/models"
- "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/setting"
@@ -59,7 +58,7 @@ func TestAddReadOnlyDeployKey(t *testing.T) {
DeployKeysPost(ctx)
assert.EqualValues(t, http.StatusFound, ctx.Resp.Status())
- db.AssertExistsAndLoadBean(t, &models.DeployKey{
+ unittest.AssertExistsAndLoadBean(t, &models.DeployKey{
Name: addKeyForm.Title,
Content: addKeyForm.Content,
Mode: models.AccessModeRead,
@@ -89,7 +88,7 @@ func TestAddReadWriteOnlyDeployKey(t *testing.T) {
DeployKeysPost(ctx)
assert.EqualValues(t, http.StatusFound, ctx.Resp.Status())
- db.AssertExistsAndLoadBean(t, &models.DeployKey{
+ unittest.AssertExistsAndLoadBean(t, &models.DeployKey{
Name: addKeyForm.Title,
Content: addKeyForm.Content,
Mode: models.AccessModeWrite,
diff --git a/routers/web/user/oauth_test.go b/routers/web/user/oauth_test.go
index e0c1bf4e77..dfdaa9a1ed 100644
--- a/routers/web/user/oauth_test.go
+++ b/routers/web/user/oauth_test.go
@@ -8,7 +8,6 @@ import (
"testing"
"code.gitea.io/gitea/models"
- "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/login"
"code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/services/auth/source/oauth2"
@@ -59,7 +58,7 @@ func TestNewAccessTokenResponse_OIDCToken(t *testing.T) {
assert.Empty(t, oidcToken.Email)
assert.False(t, oidcToken.EmailVerified)
- user := db.AssertExistsAndLoadBean(t, &models.User{ID: 5}).(*models.User)
+ user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 5}).(*models.User)
grants, err = login.GetOAuth2GrantsByUserID(user.ID)
assert.NoError(t, err)
assert.Len(t, grants, 1)