summaryrefslogtreecommitdiffstats
path: root/models/issue_label_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'models/issue_label_test.go')
-rw-r--r--models/issue_label_test.go131
1 files changed, 66 insertions, 65 deletions
diff --git a/models/issue_label_test.go b/models/issue_label_test.go
index 3dde1a4069..384965b846 100644
--- a/models/issue_label_test.go
+++ b/models/issue_label_test.go
@@ -8,29 +8,30 @@ import (
"html/template"
"testing"
+ "code.gitea.io/gitea/models/db"
"github.com/stretchr/testify/assert"
)
// TODO TestGetLabelTemplateFile
func TestLabel_CalOpenIssues(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
- label := AssertExistsAndLoadBean(t, &Label{ID: 1}).(*Label)
+ assert.NoError(t, db.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, PrepareTestDatabase())
- label := AssertExistsAndLoadBean(t, &Label{ID: 1}).(*Label)
+ assert.NoError(t, db.PrepareTestDatabase())
+ label := db.AssertExistsAndLoadBean(t, &Label{ID: 1}).(*Label)
assert.Equal(t, template.CSS("#000"), label.ForegroundColor())
- label = AssertExistsAndLoadBean(t, &Label{ID: 2}).(*Label)
+ label = db.AssertExistsAndLoadBean(t, &Label{ID: 2}).(*Label)
assert.Equal(t, template.CSS("#fff"), label.ForegroundColor())
}
func TestNewLabels(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
labels := []*Label{
{RepoID: 2, Name: "labelName2", Color: "#123456"},
{RepoID: 3, Name: "labelName3", Color: "#23456F"},
@@ -39,27 +40,27 @@ 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 {
- AssertNotExistsBean(t, label)
+ db.AssertNotExistsBean(t, label)
}
assert.NoError(t, NewLabels(labels...))
for _, label := range labels {
- AssertExistsAndLoadBean(t, label, Cond("id = ?", label.ID))
+ db.AssertExistsAndLoadBean(t, label, db.Cond("id = ?", label.ID))
}
CheckConsistencyFor(t, &Label{}, &Repository{})
}
func TestGetLabelByID(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
label, err := GetLabelByID(1)
assert.NoError(t, err)
assert.EqualValues(t, 1, label.ID)
- _, err = GetLabelByID(NonexistentID)
+ _, err = GetLabelByID(db.NonexistentID)
assert.True(t, IsErrLabelNotExist(err))
}
func TestGetLabelInRepoByName(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
label, err := GetLabelInRepoByName(1, "label1")
assert.NoError(t, err)
assert.EqualValues(t, 1, label.ID)
@@ -68,12 +69,12 @@ func TestGetLabelInRepoByName(t *testing.T) {
_, err = GetLabelInRepoByName(1, "")
assert.True(t, IsErrRepoLabelNotExist(err))
- _, err = GetLabelInRepoByName(NonexistentID, "nonexistent")
+ _, err = GetLabelInRepoByName(db.NonexistentID, "nonexistent")
assert.True(t, IsErrRepoLabelNotExist(err))
}
func TestGetLabelInRepoByNames(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
labelIDs, err := GetLabelIDsInRepoByNames(1, []string{"label1", "label2"})
assert.NoError(t, err)
@@ -84,7 +85,7 @@ func TestGetLabelInRepoByNames(t *testing.T) {
}
func TestGetLabelInRepoByNamesDiscardsNonExistentLabels(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
// label3 doesn't exists.. See labels.yml
labelIDs, err := GetLabelIDsInRepoByNames(1, []string{"label1", "label2", "label3"})
assert.NoError(t, err)
@@ -97,7 +98,7 @@ func TestGetLabelInRepoByNamesDiscardsNonExistentLabels(t *testing.T) {
}
func TestGetLabelInRepoByID(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
label, err := GetLabelInRepoByID(1, 1)
assert.NoError(t, err)
assert.EqualValues(t, 1, label.ID)
@@ -105,13 +106,13 @@ func TestGetLabelInRepoByID(t *testing.T) {
_, err = GetLabelInRepoByID(1, -1)
assert.True(t, IsErrRepoLabelNotExist(err))
- _, err = GetLabelInRepoByID(NonexistentID, NonexistentID)
+ _, err = GetLabelInRepoByID(db.NonexistentID, db.NonexistentID)
assert.True(t, IsErrRepoLabelNotExist(err))
}
func TestGetLabelsInRepoByIDs(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
- labels, err := GetLabelsInRepoByIDs(1, []int64{1, 2, NonexistentID})
+ assert.NoError(t, db.PrepareTestDatabase())
+ labels, err := GetLabelsInRepoByIDs(1, []int64{1, 2, db.NonexistentID})
assert.NoError(t, err)
if assert.Len(t, labels, 2) {
assert.EqualValues(t, 1, labels[0].ID)
@@ -120,7 +121,7 @@ func TestGetLabelsInRepoByIDs(t *testing.T) {
}
func TestGetLabelsByRepoID(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
testSuccess := func(repoID int64, sortType string, expectedIssueIDs []int64) {
labels, err := GetLabelsByRepoID(repoID, sortType, ListOptions{})
assert.NoError(t, err)
@@ -138,7 +139,7 @@ func TestGetLabelsByRepoID(t *testing.T) {
// Org versions
func TestGetLabelInOrgByName(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
label, err := GetLabelInOrgByName(3, "orglabel3")
assert.NoError(t, err)
assert.EqualValues(t, 3, label.ID)
@@ -153,12 +154,12 @@ func TestGetLabelInOrgByName(t *testing.T) {
_, err = GetLabelInOrgByName(-1, "orglabel3")
assert.True(t, IsErrOrgLabelNotExist(err))
- _, err = GetLabelInOrgByName(NonexistentID, "nonexistent")
+ _, err = GetLabelInOrgByName(db.NonexistentID, "nonexistent")
assert.True(t, IsErrOrgLabelNotExist(err))
}
func TestGetLabelInOrgByNames(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
labelIDs, err := GetLabelIDsInOrgByNames(3, []string{"orglabel3", "orglabel4"})
assert.NoError(t, err)
@@ -169,7 +170,7 @@ func TestGetLabelInOrgByNames(t *testing.T) {
}
func TestGetLabelInOrgByNamesDiscardsNonExistentLabels(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
// orglabel99 doesn't exists.. See labels.yml
labelIDs, err := GetLabelIDsInOrgByNames(3, []string{"orglabel3", "orglabel4", "orglabel99"})
assert.NoError(t, err)
@@ -182,7 +183,7 @@ func TestGetLabelInOrgByNamesDiscardsNonExistentLabels(t *testing.T) {
}
func TestGetLabelInOrgByID(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
label, err := GetLabelInOrgByID(3, 3)
assert.NoError(t, err)
assert.EqualValues(t, 3, label.ID)
@@ -196,13 +197,13 @@ func TestGetLabelInOrgByID(t *testing.T) {
_, err = GetLabelInOrgByID(-1, 3)
assert.True(t, IsErrOrgLabelNotExist(err))
- _, err = GetLabelInOrgByID(NonexistentID, NonexistentID)
+ _, err = GetLabelInOrgByID(db.NonexistentID, db.NonexistentID)
assert.True(t, IsErrOrgLabelNotExist(err))
}
func TestGetLabelsInOrgByIDs(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
- labels, err := GetLabelsInOrgByIDs(3, []int64{3, 4, NonexistentID})
+ assert.NoError(t, db.PrepareTestDatabase())
+ labels, err := GetLabelsInOrgByIDs(3, []int64{3, 4, db.NonexistentID})
assert.NoError(t, err)
if assert.Len(t, labels, 2) {
assert.EqualValues(t, 3, labels[0].ID)
@@ -211,7 +212,7 @@ func TestGetLabelsInOrgByIDs(t *testing.T) {
}
func TestGetLabelsByOrgID(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
testSuccess := func(orgID int64, sortType string, expectedIssueIDs []int64) {
labels, err := GetLabelsByOrgID(orgID, sortType, ListOptions{})
assert.NoError(t, err)
@@ -236,21 +237,21 @@ func TestGetLabelsByOrgID(t *testing.T) {
//
func TestGetLabelsByIssueID(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
labels, err := GetLabelsByIssueID(1)
assert.NoError(t, err)
if assert.Len(t, labels, 1) {
assert.EqualValues(t, 1, labels[0].ID)
}
- labels, err = GetLabelsByIssueID(NonexistentID)
+ labels, err = GetLabelsByIssueID(db.NonexistentID)
assert.NoError(t, err)
assert.Len(t, labels, 0)
}
func TestUpdateLabel(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
- label := AssertExistsAndLoadBean(t, &Label{ID: 1}).(*Label)
+ assert.NoError(t, db.PrepareTestDatabase())
+ label := db.AssertExistsAndLoadBean(t, &Label{ID: 1}).(*Label)
// make sure update wont overwrite it
update := &Label{
ID: label.ID,
@@ -261,7 +262,7 @@ func TestUpdateLabel(t *testing.T) {
label.Color = update.Color
label.Name = update.Name
assert.NoError(t, UpdateLabel(update))
- newLabel := AssertExistsAndLoadBean(t, &Label{ID: 1}).(*Label)
+ newLabel := db.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)
@@ -270,43 +271,43 @@ func TestUpdateLabel(t *testing.T) {
}
func TestDeleteLabel(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
- label := AssertExistsAndLoadBean(t, &Label{ID: 1}).(*Label)
+ assert.NoError(t, db.PrepareTestDatabase())
+ label := db.AssertExistsAndLoadBean(t, &Label{ID: 1}).(*Label)
assert.NoError(t, DeleteLabel(label.RepoID, label.ID))
- AssertNotExistsBean(t, &Label{ID: label.ID, RepoID: label.RepoID})
+ db.AssertNotExistsBean(t, &Label{ID: label.ID, RepoID: label.RepoID})
assert.NoError(t, DeleteLabel(label.RepoID, label.ID))
- AssertNotExistsBean(t, &Label{ID: label.ID})
+ db.AssertNotExistsBean(t, &Label{ID: label.ID})
- assert.NoError(t, DeleteLabel(NonexistentID, NonexistentID))
+ assert.NoError(t, DeleteLabel(db.NonexistentID, db.NonexistentID))
CheckConsistencyFor(t, &Label{}, &Repository{})
}
func TestHasIssueLabel(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
assert.True(t, HasIssueLabel(1, 1))
assert.False(t, HasIssueLabel(1, 2))
- assert.False(t, HasIssueLabel(NonexistentID, NonexistentID))
+ assert.False(t, HasIssueLabel(db.NonexistentID, db.NonexistentID))
}
func TestNewIssueLabel(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
- label := AssertExistsAndLoadBean(t, &Label{ID: 2}).(*Label)
- issue := AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue)
- doer := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
+ assert.NoError(t, db.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)
// add new IssueLabel
prevNumIssues := label.NumIssues
assert.NoError(t, NewIssueLabel(issue, label, doer))
- AssertExistsAndLoadBean(t, &IssueLabel{IssueID: issue.ID, LabelID: label.ID})
- AssertExistsAndLoadBean(t, &Comment{
+ db.AssertExistsAndLoadBean(t, &IssueLabel{IssueID: issue.ID, LabelID: label.ID})
+ db.AssertExistsAndLoadBean(t, &Comment{
Type: CommentTypeLabel,
PosterID: doer.ID,
IssueID: issue.ID,
LabelID: label.ID,
Content: "1",
})
- label = AssertExistsAndLoadBean(t, &Label{ID: 2}).(*Label)
+ label = db.AssertExistsAndLoadBean(t, &Label{ID: 2}).(*Label)
assert.EqualValues(t, prevNumIssues+1, label.NumIssues)
// re-add existing IssueLabel
@@ -315,26 +316,26 @@ func TestNewIssueLabel(t *testing.T) {
}
func TestNewIssueLabels(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
- label1 := AssertExistsAndLoadBean(t, &Label{ID: 1}).(*Label)
- label2 := AssertExistsAndLoadBean(t, &Label{ID: 2}).(*Label)
- issue := AssertExistsAndLoadBean(t, &Issue{ID: 5}).(*Issue)
- doer := AssertExistsAndLoadBean(t, &User{ID: 2}).(*User)
+ assert.NoError(t, db.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)
assert.NoError(t, NewIssueLabels(issue, []*Label{label1, label2}, doer))
- AssertExistsAndLoadBean(t, &IssueLabel{IssueID: issue.ID, LabelID: label1.ID})
- AssertExistsAndLoadBean(t, &Comment{
+ db.AssertExistsAndLoadBean(t, &IssueLabel{IssueID: issue.ID, LabelID: label1.ID})
+ db.AssertExistsAndLoadBean(t, &Comment{
Type: CommentTypeLabel,
PosterID: doer.ID,
IssueID: issue.ID,
LabelID: label1.ID,
Content: "1",
})
- AssertExistsAndLoadBean(t, &IssueLabel{IssueID: issue.ID, LabelID: label1.ID})
- label1 = AssertExistsAndLoadBean(t, &Label{ID: 1}).(*Label)
+ db.AssertExistsAndLoadBean(t, &IssueLabel{IssueID: issue.ID, LabelID: label1.ID})
+ label1 = db.AssertExistsAndLoadBean(t, &Label{ID: 1}).(*Label)
assert.EqualValues(t, 3, label1.NumIssues)
assert.EqualValues(t, 1, label1.NumClosedIssues)
- label2 = AssertExistsAndLoadBean(t, &Label{ID: 2}).(*Label)
+ label2 = db.AssertExistsAndLoadBean(t, &Label{ID: 2}).(*Label)
assert.EqualValues(t, 1, label2.NumIssues)
assert.EqualValues(t, 1, label2.NumClosedIssues)
@@ -345,15 +346,15 @@ func TestNewIssueLabels(t *testing.T) {
}
func TestDeleteIssueLabel(t *testing.T) {
- assert.NoError(t, PrepareTestDatabase())
+ assert.NoError(t, db.PrepareTestDatabase())
testSuccess := func(labelID, issueID, doerID int64) {
- label := AssertExistsAndLoadBean(t, &Label{ID: labelID}).(*Label)
- issue := AssertExistsAndLoadBean(t, &Issue{ID: issueID}).(*Issue)
- doer := AssertExistsAndLoadBean(t, &User{ID: doerID}).(*User)
+ label := db.AssertExistsAndLoadBean(t, &Label{ID: labelID}).(*Label)
+ issue := db.AssertExistsAndLoadBean(t, &Issue{ID: issueID}).(*Issue)
+ doer := db.AssertExistsAndLoadBean(t, &User{ID: doerID}).(*User)
expectedNumIssues := label.NumIssues
expectedNumClosedIssues := label.NumClosedIssues
- if BeanExists(t, &IssueLabel{IssueID: issueID, LabelID: labelID}) {
+ if db.BeanExists(t, &IssueLabel{IssueID: issueID, LabelID: labelID}) {
expectedNumIssues--
if issue.IsClosed {
expectedNumClosedIssues--
@@ -361,14 +362,14 @@ func TestDeleteIssueLabel(t *testing.T) {
}
assert.NoError(t, DeleteIssueLabel(issue, label, doer))
- AssertNotExistsBean(t, &IssueLabel{IssueID: issueID, LabelID: labelID})
- AssertExistsAndLoadBean(t, &Comment{
+ db.AssertNotExistsBean(t, &IssueLabel{IssueID: issueID, LabelID: labelID})
+ db.AssertExistsAndLoadBean(t, &Comment{
Type: CommentTypeLabel,
PosterID: doerID,
IssueID: issueID,
LabelID: labelID,
}, `content=""`)
- label = AssertExistsAndLoadBean(t, &Label{ID: labelID}).(*Label)
+ label = db.AssertExistsAndLoadBean(t, &Label{ID: labelID}).(*Label)
assert.EqualValues(t, expectedNumIssues, label.NumIssues)
assert.EqualValues(t, expectedNumClosedIssues, label.NumClosedIssues)
}