diff options
author | Ethan Koenig <ethantkoenig@gmail.com> | 2017-12-02 18:20:12 -0800 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2017-12-03 10:20:12 +0800 |
commit | 3163abedd6c3814d04b380c036ca19a7bffe908f (patch) | |
tree | 552e8bbdaa2e8b2f2c9326ae935bfdcae67d198b /models/action_test.go | |
parent | b0971ae37c255ea219c07489bc66809caa1094ef (diff) | |
download | gitea-3163abedd6c3814d04b380c036ca19a7bffe908f.tar.gz gitea-3163abedd6c3814d04b380c036ca19a7bffe908f.zip |
Fix ref parsing in commit messages (#3067)
Diffstat (limited to 'models/action_test.go')
-rw-r--r-- | models/action_test.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/models/action_test.go b/models/action_test.go index 3f29e1556c..0169179050 100644 --- a/models/action_test.go +++ b/models/action_test.go @@ -1,6 +1,7 @@ package models import ( + "fmt" "path" "strings" "testing" @@ -154,6 +155,35 @@ func TestPushCommits_AvatarLink(t *testing.T) { pushCommits.AvatarLink("nonexistent@example.com")) } +func Test_getIssueFromRef(t *testing.T) { + assert.NoError(t, PrepareTestDatabase()) + repo := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository) + for _, test := range []struct { + Ref string + ExpectedIssueID int64 + }{ + {"#2", 2}, + {"reopen #2", 2}, + {"user2/repo2#1", 4}, + {"fixes user2/repo2#1", 4}, + } { + issue, err := getIssueFromRef(repo, test.Ref) + assert.NoError(t, err) + if assert.NotNil(t, issue) { + assert.EqualValues(t, test.ExpectedIssueID, issue.ID) + } + } + + for _, badRef := range []string{ + "doesnotexist/doesnotexist#1", + fmt.Sprintf("#%d", NonexistentID), + } { + issue, err := getIssueFromRef(repo, badRef) + assert.NoError(t, err) + assert.Nil(t, issue) + } +} + func TestUpdateIssuesCommit(t *testing.T) { assert.NoError(t, PrepareTestDatabase()) pushCommits := []*PushCommit{ |