-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move issue label operations to issue service package
- Loading branch information
Showing
7 changed files
with
168 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright 2017 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package issue | ||
|
||
import ( | ||
"testing" | ||
|
||
"code.gitea.io/gitea/models" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestIssue_AddLabels(t *testing.T) { | ||
var tests = []struct { | ||
issueID int64 | ||
labelIDs []int64 | ||
doerID int64 | ||
}{ | ||
{1, []int64{1, 2}, 2}, // non-pull-request | ||
{1, []int64{}, 2}, // non-pull-request, empty | ||
{2, []int64{1, 2}, 2}, // pull-request | ||
{2, []int64{}, 1}, // pull-request, empty | ||
} | ||
for _, test := range tests { | ||
assert.NoError(t, models.PrepareTestDatabase()) | ||
issue := models.AssertExistsAndLoadBean(t, &models.AccessMode{ID: test.issueID}).(*models.Issue) | ||
labels := make([]*models.Label, len(test.labelIDs)) | ||
for i, labelID := range test.labelIDs { | ||
labels[i] = models.AssertExistsAndLoadBean(t, &models.Label{ID: labelID}).(*models.Label) | ||
} | ||
doer := models.AssertExistsAndLoadBean(t, &models.User{ID: test.doerID}).(*models.User) | ||
assert.NoError(t, AddLabels(issue, doer, labels)) | ||
for _, labelID := range test.labelIDs { | ||
models.AssertExistsAndLoadBean(t, &models.IssueLabel{IssueID: test.issueID, LabelID: labelID}) | ||
} | ||
} | ||
} | ||
|
||
func TestIssue_AddLabel(t *testing.T) { | ||
var tests = []struct { | ||
issueID int64 | ||
labelID int64 | ||
doerID int64 | ||
}{ | ||
{1, 2, 2}, // non-pull-request, not-already-added label | ||
{1, 1, 2}, // non-pull-request, already-added label | ||
{2, 2, 2}, // pull-request, not-already-added label | ||
{2, 1, 2}, // pull-request, already-added label | ||
} | ||
for _, test := range tests { | ||
assert.NoError(t, models.PrepareTestDatabase()) | ||
issue := models.AssertExistsAndLoadBean(t, &models.Issue{ID: test.issueID}).(*models.Issue) | ||
label := models.AssertExistsAndLoadBean(t, &models.Label{ID: test.labelID}).(*models.Label) | ||
doer := models.AssertExistsAndLoadBean(t, &models.User{ID: test.doerID}).(*models.User) | ||
assert.NoError(t, AddLabel(issue, doer, label)) | ||
models.AssertExistsAndLoadBean(t, &models.IssueLabel{IssueID: test.issueID, LabelID: test.labelID}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright 2019 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package issue | ||
|
||
import ( | ||
"path/filepath" | ||
"testing" | ||
|
||
"code.gitea.io/gitea/models" | ||
) | ||
|
||
func TestMain(m *testing.M) { | ||
models.MainTest(m, filepath.Join("..", "..")) | ||
} |