summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorEthan Koenig <etk39@cornell.edu>2017-03-11 03:46:23 -0500
committerLunny Xiao <xiaolunwen@gmail.com>2017-03-11 16:46:23 +0800
commit1e3548b7e764c60aad2eb315a65e146264c11a7d (patch)
tree47676638358f6eede398aec09a71cc084bbf95ca /models
parent64214a9426c93040225c2df46f7f7809e2470b20 (diff)
downloadgitea-1e3548b7e764c60aad2eb315a65e146264c11a7d.tar.gz
gitea-1e3548b7e764c60aad2eb315a65e146264c11a7d.zip
Unit tests for issue_list (#1209)
Diffstat (limited to 'models')
-rw-r--r--models/issue_list_test.go65
1 files changed, 65 insertions, 0 deletions
diff --git a/models/issue_list_test.go b/models/issue_list_test.go
new file mode 100644
index 0000000000..958e074662
--- /dev/null
+++ b/models/issue_list_test.go
@@ -0,0 +1,65 @@
+// 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 TestIssueList_LoadRepositories(t *testing.T) {
+ assert.NoError(t, PrepareTestDatabase())
+
+ issueList := IssueList{
+ AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue),
+ AssertExistsAndLoadBean(t, &Issue{ID: 2}).(*Issue),
+ AssertExistsAndLoadBean(t, &Issue{ID: 4}).(*Issue),
+ }
+
+ repos, err := issueList.LoadRepositories()
+ assert.NoError(t, err)
+ assert.Len(t, repos, 2)
+ for _, issue := range issueList {
+ assert.EqualValues(t, issue.RepoID, issue.Repo.ID)
+ }
+}
+
+func TestIssueList_LoadAttributes(t *testing.T) {
+ assert.NoError(t, PrepareTestDatabase())
+
+ issueList := IssueList{
+ AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue),
+ AssertExistsAndLoadBean(t, &Issue{ID: 2}).(*Issue),
+ AssertExistsAndLoadBean(t, &Issue{ID: 4}).(*Issue),
+ }
+
+ assert.NoError(t, issueList.LoadAttributes())
+ for _, issue := range issueList {
+ assert.EqualValues(t, issue.RepoID, issue.Repo.ID)
+ for _, label := range issue.Labels {
+ assert.EqualValues(t, issue.RepoID, label.RepoID)
+ AssertExistsAndLoadBean(t, &IssueLabel{IssueID: issue.ID, LabelID: label.ID})
+ }
+ if issue.PosterID > 0 {
+ assert.EqualValues(t, issue.PosterID, issue.Poster.ID)
+ }
+ if issue.AssigneeID > 0 {
+ assert.EqualValues(t, issue.AssigneeID, issue.Assignee.ID)
+ }
+ if issue.MilestoneID > 0 {
+ assert.EqualValues(t, issue.MilestoneID, issue.Milestone.ID)
+ }
+ if issue.IsPull {
+ assert.EqualValues(t, issue.ID, issue.PullRequest.IssueID)
+ }
+ for _, attachment := range issue.Attachments {
+ assert.EqualValues(t, issue.ID, attachment.IssueID)
+ }
+ for _, comment := range issue.Comments {
+ assert.EqualValues(t, issue.ID, comment.IssueID)
+ }
+ }
+}