Skip to content

Commit 1e3548b

Browse files
ethantkoeniglunny
authored andcommitted
Unit tests for issue_list (#1209)
1 parent 64214a9 commit 1e3548b

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

models/issue_list_test.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Copyright 2017 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package models
6+
7+
import (
8+
"testing"
9+
10+
"github.com/stretchr/testify/assert"
11+
)
12+
13+
func TestIssueList_LoadRepositories(t *testing.T) {
14+
assert.NoError(t, PrepareTestDatabase())
15+
16+
issueList := IssueList{
17+
AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue),
18+
AssertExistsAndLoadBean(t, &Issue{ID: 2}).(*Issue),
19+
AssertExistsAndLoadBean(t, &Issue{ID: 4}).(*Issue),
20+
}
21+
22+
repos, err := issueList.LoadRepositories()
23+
assert.NoError(t, err)
24+
assert.Len(t, repos, 2)
25+
for _, issue := range issueList {
26+
assert.EqualValues(t, issue.RepoID, issue.Repo.ID)
27+
}
28+
}
29+
30+
func TestIssueList_LoadAttributes(t *testing.T) {
31+
assert.NoError(t, PrepareTestDatabase())
32+
33+
issueList := IssueList{
34+
AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue),
35+
AssertExistsAndLoadBean(t, &Issue{ID: 2}).(*Issue),
36+
AssertExistsAndLoadBean(t, &Issue{ID: 4}).(*Issue),
37+
}
38+
39+
assert.NoError(t, issueList.LoadAttributes())
40+
for _, issue := range issueList {
41+
assert.EqualValues(t, issue.RepoID, issue.Repo.ID)
42+
for _, label := range issue.Labels {
43+
assert.EqualValues(t, issue.RepoID, label.RepoID)
44+
AssertExistsAndLoadBean(t, &IssueLabel{IssueID: issue.ID, LabelID: label.ID})
45+
}
46+
if issue.PosterID > 0 {
47+
assert.EqualValues(t, issue.PosterID, issue.Poster.ID)
48+
}
49+
if issue.AssigneeID > 0 {
50+
assert.EqualValues(t, issue.AssigneeID, issue.Assignee.ID)
51+
}
52+
if issue.MilestoneID > 0 {
53+
assert.EqualValues(t, issue.MilestoneID, issue.Milestone.ID)
54+
}
55+
if issue.IsPull {
56+
assert.EqualValues(t, issue.ID, issue.PullRequest.IssueID)
57+
}
58+
for _, attachment := range issue.Attachments {
59+
assert.EqualValues(t, issue.ID, attachment.IssueID)
60+
}
61+
for _, comment := range issue.Comments {
62+
assert.EqualValues(t, issue.ID, comment.IssueID)
63+
}
64+
}
65+
}

0 commit comments

Comments
 (0)