summaryrefslogtreecommitdiffstats
path: root/models/issue_label_test.go
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 /models/issue_label_test.go
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 'models/issue_label_test.go')
-rw-r--r--models/issue_label_test.go96
1 files changed, 48 insertions, 48 deletions
diff --git a/models/issue_label_test.go b/models/issue_label_test.go
index c77ddfefaf..658c459ba5 100644
--- a/models/issue_label_test.go
+++ b/models/issue_label_test.go
@@ -17,17 +17,17 @@ import (
func TestLabel_CalOpenIssues(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
- label := db.AssertExistsAndLoadBean(t, &Label{ID: 1}).(*Label)
+ label := unittest.AssertExistsAndLoadBean(t, &Label{ID: 1}).(*Label)
label.CalOpenIssues()
assert.EqualValues(t, 2, label.NumOpenIssues)
}
func TestLabel_ForegroundColor(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
- label := db.AssertExistsAndLoadBean(t, &Label{ID: 1}).(*Label)
+ label := unittest.AssertExistsAndLoadBean(t, &Label{ID: 1}).(*Label)
assert.Equal(t, template.CSS("#000"), label.ForegroundColor())
- label = db.AssertExistsAndLoadBean(t, &Label{ID: 2}).(*Label)
+ label = unittest.AssertExistsAndLoadBean(t, &Label{ID: 2}).(*Label)
assert.Equal(t, template.CSS("#fff"), label.ForegroundColor())
}
@@ -41,13 +41,13 @@ func TestNewLabels(t *testing.T) {
assert.Error(t, NewLabel(&Label{RepoID: 3, Name: "invalid Color", Color: "123456"}))
assert.Error(t, NewLabel(&Label{RepoID: 3, Name: "invalid Color", Color: "#12345G"}))
for _, label := range labels {
- db.AssertNotExistsBean(t, label)
+ unittest.AssertNotExistsBean(t, label)
}
assert.NoError(t, NewLabels(labels...))
for _, label := range labels {
- db.AssertExistsAndLoadBean(t, label, db.Cond("id = ?", label.ID))
+ unittest.AssertExistsAndLoadBean(t, label, unittest.Cond("id = ?", label.ID))
}
- CheckConsistencyFor(t, &Label{}, &Repository{})
+ unittest.CheckConsistencyFor(t, &Label{}, &Repository{})
}
func TestGetLabelByID(t *testing.T) {
@@ -56,7 +56,7 @@ func TestGetLabelByID(t *testing.T) {
assert.NoError(t, err)
assert.EqualValues(t, 1, label.ID)
- _, err = GetLabelByID(db.NonexistentID)
+ _, err = GetLabelByID(unittest.NonexistentID)
assert.True(t, IsErrLabelNotExist(err))
}
@@ -70,7 +70,7 @@ func TestGetLabelInRepoByName(t *testing.T) {
_, err = GetLabelInRepoByName(1, "")
assert.True(t, IsErrRepoLabelNotExist(err))
- _, err = GetLabelInRepoByName(db.NonexistentID, "nonexistent")
+ _, err = GetLabelInRepoByName(unittest.NonexistentID, "nonexistent")
assert.True(t, IsErrRepoLabelNotExist(err))
}
@@ -107,13 +107,13 @@ func TestGetLabelInRepoByID(t *testing.T) {
_, err = GetLabelInRepoByID(1, -1)
assert.True(t, IsErrRepoLabelNotExist(err))
- _, err = GetLabelInRepoByID(db.NonexistentID, db.NonexistentID)
+ _, err = GetLabelInRepoByID(unittest.NonexistentID, unittest.NonexistentID)
assert.True(t, IsErrRepoLabelNotExist(err))
}
func TestGetLabelsInRepoByIDs(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
- labels, err := GetLabelsInRepoByIDs(1, []int64{1, 2, db.NonexistentID})
+ labels, err := GetLabelsInRepoByIDs(1, []int64{1, 2, unittest.NonexistentID})
assert.NoError(t, err)
if assert.Len(t, labels, 2) {
assert.EqualValues(t, 1, labels[0].ID)
@@ -155,7 +155,7 @@ func TestGetLabelInOrgByName(t *testing.T) {
_, err = GetLabelInOrgByName(-1, "orglabel3")
assert.True(t, IsErrOrgLabelNotExist(err))
- _, err = GetLabelInOrgByName(db.NonexistentID, "nonexistent")
+ _, err = GetLabelInOrgByName(unittest.NonexistentID, "nonexistent")
assert.True(t, IsErrOrgLabelNotExist(err))
}
@@ -198,13 +198,13 @@ func TestGetLabelInOrgByID(t *testing.T) {
_, err = GetLabelInOrgByID(-1, 3)
assert.True(t, IsErrOrgLabelNotExist(err))
- _, err = GetLabelInOrgByID(db.NonexistentID, db.NonexistentID)
+ _, err = GetLabelInOrgByID(unittest.NonexistentID, unittest.NonexistentID)
assert.True(t, IsErrOrgLabelNotExist(err))
}
func TestGetLabelsInOrgByIDs(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
- labels, err := GetLabelsInOrgByIDs(3, []int64{3, 4, db.NonexistentID})
+ labels, err := GetLabelsInOrgByIDs(3, []int64{3, 4, unittest.NonexistentID})
assert.NoError(t, err)
if assert.Len(t, labels, 2) {
assert.EqualValues(t, 3, labels[0].ID)
@@ -245,14 +245,14 @@ func TestGetLabelsByIssueID(t *testing.T) {
assert.EqualValues(t, 1, labels[0].ID)
}
- labels, err = GetLabelsByIssueID(db.NonexistentID)
+ labels, err = GetLabelsByIssueID(unittest.NonexistentID)
assert.NoError(t, err)
assert.Len(t, labels, 0)
}
func TestUpdateLabel(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
- label := db.AssertExistsAndLoadBean(t, &Label{ID: 1}).(*Label)
+ label := unittest.AssertExistsAndLoadBean(t, &Label{ID: 1}).(*Label)
// make sure update wont overwrite it
update := &Label{
ID: label.ID,
@@ -263,99 +263,99 @@ func TestUpdateLabel(t *testing.T) {
label.Color = update.Color
label.Name = update.Name
assert.NoError(t, UpdateLabel(update))
- newLabel := db.AssertExistsAndLoadBean(t, &Label{ID: 1}).(*Label)
+ newLabel := unittest.AssertExistsAndLoadBean(t, &Label{ID: 1}).(*Label)
assert.EqualValues(t, label.ID, newLabel.ID)
assert.EqualValues(t, label.Color, newLabel.Color)
assert.EqualValues(t, label.Name, newLabel.Name)
assert.EqualValues(t, label.Description, newLabel.Description)
- CheckConsistencyFor(t, &Label{}, &Repository{})
+ unittest.CheckConsistencyFor(t, &Label{}, &Repository{})
}
func TestDeleteLabel(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
- label := db.AssertExistsAndLoadBean(t, &Label{ID: 1}).(*Label)
+ label := unittest.AssertExistsAndLoadBean(t, &Label{ID: 1}).(*Label)
assert.NoError(t, DeleteLabel(label.RepoID, label.ID))
- db.AssertNotExistsBean(t, &Label{ID: label.ID, RepoID: label.RepoID})
+ unittest.AssertNotExistsBean(t, &Label{ID: label.ID, RepoID: label.RepoID})
assert.NoError(t, DeleteLabel(label.RepoID, label.ID))
- db.AssertNotExistsBean(t, &Label{ID: label.ID})
+ unittest.AssertNotExistsBean(t, &Label{ID: label.ID})
- assert.NoError(t, DeleteLabel(db.NonexistentID, db.NonexistentID))
- CheckConsistencyFor(t, &Label{}, &Repository{})
+ assert.NoError(t, DeleteLabel(unittest.NonexistentID, unittest.NonexistentID))
+ unittest.CheckConsistencyFor(t, &Label{}, &Repository{})
}
func TestHasIssueLabel(t *testing.T) {
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))
+ assert.False(t, HasIssueLabel(unittest.NonexistentID, unittest.NonexistentID))
}
func TestNewIssueLabel(t *testing.T) {
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)
+ label := unittest.AssertExistsAndLoadBean(t, &Label{ID: 2}).(*Label)
+ issue := unittest.AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue)
+ doer := unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
// add new IssueLabel
prevNumIssues := label.NumIssues
assert.NoError(t, NewIssueLabel(issue, label, doer))
- db.AssertExistsAndLoadBean(t, &IssueLabel{IssueID: issue.ID, LabelID: label.ID})
- db.AssertExistsAndLoadBean(t, &Comment{
+ unittest.AssertExistsAndLoadBean(t, &IssueLabel{IssueID: issue.ID, LabelID: label.ID})
+ unittest.AssertExistsAndLoadBean(t, &Comment{
Type: CommentTypeLabel,
PosterID: doer.ID,
IssueID: issue.ID,
LabelID: label.ID,
Content: "1",
})
- label = db.AssertExistsAndLoadBean(t, &Label{ID: 2}).(*Label)
+ label = unittest.AssertExistsAndLoadBean(t, &Label{ID: 2}).(*Label)
assert.EqualValues(t, prevNumIssues+1, label.NumIssues)
// re-add existing IssueLabel
assert.NoError(t, NewIssueLabel(issue, label, doer))
- CheckConsistencyFor(t, &Issue{}, &Label{})
+ unittest.CheckConsistencyFor(t, &Issue{}, &Label{})
}
func TestNewIssueLabels(t *testing.T) {
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)
- doer := db.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
+ label1 := unittest.AssertExistsAndLoadBean(t, &Label{ID: 1}).(*Label)
+ label2 := unittest.AssertExistsAndLoadBean(t, &Label{ID: 2}).(*Label)
+ issue := unittest.AssertExistsAndLoadBean(t, &Issue{ID: 5}).(*Issue)
+ doer := unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
assert.NoError(t, NewIssueLabels(issue, []*Label{label1, label2}, doer))
- db.AssertExistsAndLoadBean(t, &IssueLabel{IssueID: issue.ID, LabelID: label1.ID})
- db.AssertExistsAndLoadBean(t, &Comment{
+ unittest.AssertExistsAndLoadBean(t, &IssueLabel{IssueID: issue.ID, LabelID: label1.ID})
+ unittest.AssertExistsAndLoadBean(t, &Comment{
Type: CommentTypeLabel,
PosterID: doer.ID,
IssueID: issue.ID,
LabelID: label1.ID,
Content: "1",
})
- db.AssertExistsAndLoadBean(t, &IssueLabel{IssueID: issue.ID, LabelID: label1.ID})
- label1 = db.AssertExistsAndLoadBean(t, &Label{ID: 1}).(*Label)
+ unittest.AssertExistsAndLoadBean(t, &IssueLabel{IssueID: issue.ID, LabelID: label1.ID})
+ label1 = unittest.AssertExistsAndLoadBean(t, &Label{ID: 1}).(*Label)
assert.EqualValues(t, 3, label1.NumIssues)
assert.EqualValues(t, 1, label1.NumClosedIssues)
- label2 = db.AssertExistsAndLoadBean(t, &Label{ID: 2}).(*Label)
+ label2 = unittest.AssertExistsAndLoadBean(t, &Label{ID: 2}).(*Label)
assert.EqualValues(t, 1, label2.NumIssues)
assert.EqualValues(t, 1, label2.NumClosedIssues)
// corner case: test empty slice
assert.NoError(t, NewIssueLabels(issue, []*Label{}, doer))
- CheckConsistencyFor(t, &Issue{}, &Label{})
+ unittest.CheckConsistencyFor(t, &Issue{}, &Label{})
}
func TestDeleteIssueLabel(t *testing.T) {
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)
- doer := db.AssertExistsAndLoadBean(t, &User{ID: doerID}).(*User)
+ label := unittest.AssertExistsAndLoadBean(t, &Label{ID: labelID}).(*Label)
+ issue := unittest.AssertExistsAndLoadBean(t, &Issue{ID: issueID}).(*Issue)
+ doer := unittest.AssertExistsAndLoadBean(t, &User{ID: doerID}).(*User)
expectedNumIssues := label.NumIssues
expectedNumClosedIssues := label.NumClosedIssues
- if db.BeanExists(t, &IssueLabel{IssueID: issueID, LabelID: labelID}) {
+ if unittest.BeanExists(t, &IssueLabel{IssueID: issueID, LabelID: labelID}) {
expectedNumIssues--
if issue.IsClosed {
expectedNumClosedIssues--
@@ -363,14 +363,14 @@ func TestDeleteIssueLabel(t *testing.T) {
}
assert.NoError(t, DeleteIssueLabel(issue, label, doer))
- db.AssertNotExistsBean(t, &IssueLabel{IssueID: issueID, LabelID: labelID})
- db.AssertExistsAndLoadBean(t, &Comment{
+ unittest.AssertNotExistsBean(t, &IssueLabel{IssueID: issueID, LabelID: labelID})
+ unittest.AssertExistsAndLoadBean(t, &Comment{
Type: CommentTypeLabel,
PosterID: doerID,
IssueID: issueID,
LabelID: labelID,
}, `content=""`)
- label = db.AssertExistsAndLoadBean(t, &Label{ID: labelID}).(*Label)
+ label = unittest.AssertExistsAndLoadBean(t, &Label{ID: labelID}).(*Label)
assert.EqualValues(t, expectedNumIssues, label.NumIssues)
assert.EqualValues(t, expectedNumClosedIssues, label.NumClosedIssues)
}
@@ -378,5 +378,5 @@ func TestDeleteIssueLabel(t *testing.T) {
testSuccess(2, 5, 2)
testSuccess(1, 1, 2) // delete non-existent IssueLabel
- CheckConsistencyFor(t, &Issue{}, &Label{})
+ unittest.CheckConsistencyFor(t, &Issue{}, &Label{})
}