diff options
author | Ethan Koenig <etk39@cornell.edu> | 2017-02-27 20:35:55 -0500 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2017-02-28 09:35:55 +0800 |
commit | cf80e191578618d94f32a0d1dece3169c4f99bf2 (patch) | |
tree | 03585177aa87d692324758c45c09d6b835f79298 /models/issue_test.go | |
parent | a2019775903902622dc80c2231f105e3213f8a60 (diff) | |
download | gitea-cf80e191578618d94f32a0d1dece3169c4f99bf2.tar.gz gitea-cf80e191578618d94f32a0d1dece3169c4f99bf2.zip |
Optimize and unit test Issue_ReplaceLabels (#1080)
Diffstat (limited to 'models/issue_test.go')
-rw-r--r-- | models/issue_test.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/models/issue_test.go b/models/issue_test.go new file mode 100644 index 0000000000..646a1a5a9a --- /dev/null +++ b/models/issue_test.go @@ -0,0 +1,35 @@ +// 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 models + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestIssue_ReplaceLabels(t *testing.T) { + assert.NoError(t, PrepareTestDatabase()) + + testSuccess := func(issueID int64, labelIDs []int64) { + issue := AssertExistsAndLoadBean(t, &Issue{ID: issueID}).(*Issue) + repo := AssertExistsAndLoadBean(t, &Repository{ID: issue.RepoID}).(*Repository) + doer := AssertExistsAndLoadBean(t, &User{ID: repo.OwnerID}).(*User) + + labels := make([]*Label, len(labelIDs)) + for i, labelID := range labelIDs { + labels[i] = AssertExistsAndLoadBean(t, &Label{ID: labelID, RepoID: repo.ID}).(*Label) + } + assert.NoError(t, issue.ReplaceLabels(labels, doer)) + AssertCount(t, &IssueLabel{IssueID: issueID}, len(labelIDs)) + for _, labelID := range labelIDs { + AssertExistsAndLoadBean(t, &IssueLabel{IssueID: issueID, LabelID: labelID}) + } + } + + testSuccess(1, []int64{2}) + testSuccess(1, []int64{1, 2}) + testSuccess(1, []int64{}) +} |