diff options
author | 6543 <6543@obermui.de> | 2020-01-31 22:13:51 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-31 16:13:51 -0500 |
commit | 8d43563a320ded0ffc0b9d66020ed3451c187259 (patch) | |
tree | 323764c39e828d1d54e886fd24da035d89483056 /modules/convert/pull_test.go | |
parent | 13bc82009c2def4e729f11340e74a14d6c6b32e8 (diff) | |
download | gitea-8d43563a320ded0ffc0b9d66020ed3451c187259.tar.gz gitea-8d43563a320ded0ffc0b9d66020ed3451c187259.zip |
[BugFix] [API] Pull.API.Convert: Only try to get HeadBranch if HeadRepo exist (#10029)
* only try to get HeadBranch if HeadRepo exist
* impruve
* no nil error
* add TEST
* correct error msg
Diffstat (limited to 'modules/convert/pull_test.go')
-rw-r--r-- | modules/convert/pull_test.go | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/modules/convert/pull_test.go b/modules/convert/pull_test.go index 9055d555e8..fe82a61bd4 100644 --- a/modules/convert/pull_test.go +++ b/modules/convert/pull_test.go @@ -13,6 +13,7 @@ import ( ) func TestPullRequest_APIFormat(t *testing.T) { + //with HeadRepo assert.NoError(t, models.PrepareTestDatabase()) pr := models.AssertExistsAndLoadBean(t, &models.PullRequest{ID: 1}).(*models.PullRequest) assert.NoError(t, pr.LoadAttributes()) @@ -20,4 +21,16 @@ func TestPullRequest_APIFormat(t *testing.T) { apiPullRequest := ToAPIPullRequest(pr) assert.NotNil(t, apiPullRequest) assert.Nil(t, apiPullRequest.Head) + + //withOut HeadRepo + pr = models.AssertExistsAndLoadBean(t, &models.PullRequest{ID: 1}).(*models.PullRequest) + assert.NoError(t, pr.LoadIssue()) + assert.NoError(t, pr.LoadAttributes()) + // simulate fork deletion + pr.HeadRepo = nil + pr.HeadRepoID = 100000 + apiPullRequest = ToAPIPullRequest(pr) + assert.NotNil(t, apiPullRequest) + assert.Nil(t, apiPullRequest.Head.Repository) + assert.EqualValues(t, -1, apiPullRequest.Head.RepoID) } |