diff options
author | Ethan Koenig <etk39@cornell.edu> | 2017-07-26 00:16:45 -0700 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2017-07-26 15:16:45 +0800 |
commit | 48898e5d0b9ed678b0373b28a5aefa8b5405d37f (patch) | |
tree | d2e9477c5336b3233dda94561cbcf977100a6cb9 /models/issue_test.go | |
parent | dde0052ca2c478f298942f6fbbe88d27259374ae (diff) | |
download | gitea-48898e5d0b9ed678b0373b28a5aefa8b5405d37f.tar.gz gitea-48898e5d0b9ed678b0373b28a5aefa8b5405d37f.zip |
Fix PR nil-dereference bug (#2195)
* Fix PR nil-dereference bug
* Revert to original error format
Diffstat (limited to 'models/issue_test.go')
-rw-r--r-- | models/issue_test.go | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/models/issue_test.go b/models/issue_test.go index e335014ca5..d135b534df 100644 --- a/models/issue_test.go +++ b/models/issue_test.go @@ -81,3 +81,68 @@ func TestGetParticipantsByIssueID(t *testing.T) { // Users 3 and 5 made actual comments (see fixtures/comment.yml) checkParticipants(1, []int{3, 5}) } + +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, PrepareTestDatabase()) + issue := AssertExistsAndLoadBean(t, &Issue{ID: test.issueID}).(*Issue) + label := AssertExistsAndLoadBean(t, &Label{ID: test.labelID}).(*Label) + doer := AssertExistsAndLoadBean(t, &User{ID: test.doerID}).(*User) + assert.NoError(t, issue.AddLabel(doer, label)) + AssertExistsAndLoadBean(t, &IssueLabel{IssueID: test.issueID, LabelID: test.labelID}) + } +} + +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, PrepareTestDatabase()) + issue := AssertExistsAndLoadBean(t, &Issue{ID: test.issueID}).(*Issue) + labels := make([]*Label, len(test.labelIDs)) + for i, labelID := range test.labelIDs { + labels[i] = AssertExistsAndLoadBean(t, &Label{ID: labelID}).(*Label) + } + doer := AssertExistsAndLoadBean(t, &User{ID: test.doerID}).(*User) + assert.NoError(t, issue.AddLabels(doer, labels)) + for _, labelID := range test.labelIDs { + AssertExistsAndLoadBean(t, &IssueLabel{IssueID: test.issueID, LabelID: labelID}) + } + } +} + +func TestIssue_ClearLabels(t *testing.T) { + var tests = []struct { + issueID int64 + doerID int64 + }{ + {1, 2}, // non-pull-request, has labels + {2, 2}, // pull-request, has labels + {3, 2}, // pull-request, has no labels + } + for _, test := range tests { + assert.NoError(t, PrepareTestDatabase()) + issue := AssertExistsAndLoadBean(t, &Issue{ID: test.issueID}).(*Issue) + doer := AssertExistsAndLoadBean(t, &User{ID: test.doerID}).(*User) + assert.NoError(t, issue.ClearLabels(doer)) + AssertNotExistsBean(t, &IssueLabel{IssueID: test.issueID}) + } +} |