aboutsummaryrefslogtreecommitdiffstats
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.go111
1 files changed, 106 insertions, 5 deletions
diff --git a/models/issue_label_test.go b/models/issue_label_test.go
index 6f51473fcb..8afba779e0 100644
--- a/models/issue_label_test.go
+++ b/models/issue_label_test.go
@@ -66,10 +66,10 @@ func TestGetLabelInRepoByName(t *testing.T) {
assert.Equal(t, "label1", label.Name)
_, err = GetLabelInRepoByName(1, "")
- assert.True(t, IsErrLabelNotExist(err))
+ assert.True(t, IsErrRepoLabelNotExist(err))
_, err = GetLabelInRepoByName(NonexistentID, "nonexistent")
- assert.True(t, IsErrLabelNotExist(err))
+ assert.True(t, IsErrRepoLabelNotExist(err))
}
func TestGetLabelInRepoByNames(t *testing.T) {
@@ -103,10 +103,10 @@ func TestGetLabelInRepoByID(t *testing.T) {
assert.EqualValues(t, 1, label.ID)
_, err = GetLabelInRepoByID(1, -1)
- assert.True(t, IsErrLabelNotExist(err))
+ assert.True(t, IsErrRepoLabelNotExist(err))
_, err = GetLabelInRepoByID(NonexistentID, NonexistentID)
- assert.True(t, IsErrLabelNotExist(err))
+ assert.True(t, IsErrRepoLabelNotExist(err))
}
func TestGetLabelsInRepoByIDs(t *testing.T) {
@@ -135,6 +135,107 @@ func TestGetLabelsByRepoID(t *testing.T) {
testSuccess(1, "default", []int64{1, 2})
}
+// Org vrsions
+
+func TestGetLabelInOrgByName(t *testing.T) {
+ assert.NoError(t, PrepareTestDatabase())
+ label, err := GetLabelInOrgByName(3, "orglabel3")
+ assert.NoError(t, err)
+ assert.EqualValues(t, 3, label.ID)
+ assert.Equal(t, "orglabel3", label.Name)
+
+ _, err = GetLabelInOrgByName(3, "")
+ assert.True(t, IsErrOrgLabelNotExist(err))
+
+ _, err = GetLabelInOrgByName(0, "orglabel3")
+ assert.True(t, IsErrOrgLabelNotExist(err))
+
+ _, err = GetLabelInOrgByName(-1, "orglabel3")
+ assert.True(t, IsErrOrgLabelNotExist(err))
+
+ _, err = GetLabelInOrgByName(NonexistentID, "nonexistent")
+ assert.True(t, IsErrOrgLabelNotExist(err))
+}
+
+func TestGetLabelInOrgByNames(t *testing.T) {
+ assert.NoError(t, PrepareTestDatabase())
+ labelIDs, err := GetLabelIDsInOrgByNames(3, []string{"orglabel3", "orglabel4"})
+ assert.NoError(t, err)
+
+ assert.Len(t, labelIDs, 2)
+
+ assert.Equal(t, int64(3), labelIDs[0])
+ assert.Equal(t, int64(4), labelIDs[1])
+}
+
+func TestGetLabelInOrgByNamesDiscardsNonExistentLabels(t *testing.T) {
+ assert.NoError(t, PrepareTestDatabase())
+ // orglabel99 doesn't exists.. See labels.yml
+ labelIDs, err := GetLabelIDsInOrgByNames(3, []string{"orglabel3", "orglabel4", "orglabel99"})
+ assert.NoError(t, err)
+
+ assert.Len(t, labelIDs, 2)
+
+ assert.Equal(t, int64(3), labelIDs[0])
+ assert.Equal(t, int64(4), labelIDs[1])
+ assert.NoError(t, err)
+}
+
+func TestGetLabelInOrgByID(t *testing.T) {
+ assert.NoError(t, PrepareTestDatabase())
+ label, err := GetLabelInOrgByID(3, 3)
+ assert.NoError(t, err)
+ assert.EqualValues(t, 3, label.ID)
+
+ _, err = GetLabelInOrgByID(3, -1)
+ assert.True(t, IsErrOrgLabelNotExist(err))
+
+ _, err = GetLabelInOrgByID(0, 3)
+ assert.True(t, IsErrOrgLabelNotExist(err))
+
+ _, err = GetLabelInOrgByID(-1, 3)
+ assert.True(t, IsErrOrgLabelNotExist(err))
+
+ _, err = GetLabelInOrgByID(NonexistentID, 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, err)
+ if assert.Len(t, labels, 2) {
+ assert.EqualValues(t, 3, labels[0].ID)
+ assert.EqualValues(t, 4, labels[1].ID)
+ }
+}
+
+func TestGetLabelsByOrgID(t *testing.T) {
+ assert.NoError(t, PrepareTestDatabase())
+ testSuccess := func(orgID int64, sortType string, expectedIssueIDs []int64) {
+ labels, err := GetLabelsByOrgID(orgID, sortType, ListOptions{})
+ assert.NoError(t, err)
+ assert.Len(t, labels, len(expectedIssueIDs))
+ for i, label := range labels {
+ assert.EqualValues(t, expectedIssueIDs[i], label.ID)
+ }
+ }
+ testSuccess(3, "leastissues", []int64{3, 4})
+ testSuccess(3, "mostissues", []int64{4, 3})
+ testSuccess(3, "reversealphabetically", []int64{4, 3})
+ testSuccess(3, "default", []int64{3, 4})
+
+ var err error
+ _, err = GetLabelsByOrgID(0, "leastissues", ListOptions{})
+ assert.True(t, IsErrOrgLabelNotExist(err))
+
+ _, err = GetLabelsByOrgID(-1, "leastissues", ListOptions{})
+ assert.True(t, IsErrOrgLabelNotExist(err))
+
+}
+
+//
+
func TestGetLabelsByIssueID(t *testing.T) {
assert.NoError(t, PrepareTestDatabase())
labels, err := GetLabelsByIssueID(1)
@@ -166,7 +267,7 @@ func TestDeleteLabel(t *testing.T) {
AssertNotExistsBean(t, &Label{ID: label.ID, RepoID: label.RepoID})
assert.NoError(t, DeleteLabel(label.RepoID, label.ID))
- AssertNotExistsBean(t, &Label{ID: label.ID, RepoID: label.RepoID})
+ AssertNotExistsBean(t, &Label{ID: label.ID})
assert.NoError(t, DeleteLabel(NonexistentID, NonexistentID))
CheckConsistencyFor(t, &Label{}, &Repository{})