Decouple unit test, remove intermediate unittestbridge
package (#17662)
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
parent
23bd7b1211
commit
81926d61db
151 changed files with 1719 additions and 1781 deletions
|
@ -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))
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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{})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue