mirror of https://github.com/go-gitea/gitea
Git with a cup of tea, painless self-hosted git service
Mirror for internal git.with.parts use
https://git.with.parts
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.6 KiB
49 lines
1.6 KiB
5 years ago
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
||
2 years ago
|
// SPDX-License-Identifier: MIT
|
||
5 years ago
|
|
||
|
package convert
|
||
|
|
||
|
import (
|
||
|
"testing"
|
||
|
|
||
2 years ago
|
"code.gitea.io/gitea/models/db"
|
||
2 years ago
|
issues_model "code.gitea.io/gitea/models/issues"
|
||
3 years ago
|
"code.gitea.io/gitea/models/perm"
|
||
3 years ago
|
repo_model "code.gitea.io/gitea/models/repo"
|
||
3 years ago
|
"code.gitea.io/gitea/models/unittest"
|
||
3 years ago
|
"code.gitea.io/gitea/modules/git"
|
||
5 years ago
|
"code.gitea.io/gitea/modules/structs"
|
||
5 years ago
|
|
||
|
"github.com/stretchr/testify/assert"
|
||
|
)
|
||
|
|
||
|
func TestPullRequest_APIFormat(t *testing.T) {
|
||
3 years ago
|
// with HeadRepo
|
||
3 years ago
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||
2 years ago
|
headRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
||
|
pr := unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 1})
|
||
2 years ago
|
assert.NoError(t, pr.LoadAttributes(db.DefaultContext))
|
||
|
assert.NoError(t, pr.LoadIssue(db.DefaultContext))
|
||
3 years ago
|
apiPullRequest := ToAPIPullRequest(git.DefaultContext, pr, nil)
|
||
5 years ago
|
assert.NotNil(t, apiPullRequest)
|
||
5 years ago
|
assert.EqualValues(t, &structs.PRBranchInfo{
|
||
|
Name: "branch1",
|
||
|
Ref: "refs/pull/2/head",
|
||
|
Sha: "4a357436d925b5c974181ff12a994538ddc5a269",
|
||
|
RepoID: 1,
|
||
2 years ago
|
Repository: ToRepo(db.DefaultContext, headRepo, perm.AccessModeRead),
|
||
5 years ago
|
}, apiPullRequest.Head)
|
||
5 years ago
|
|
||
3 years ago
|
// withOut HeadRepo
|
||
2 years ago
|
pr = unittest.AssertExistsAndLoadBean(t, &issues_model.PullRequest{ID: 1})
|
||
2 years ago
|
assert.NoError(t, pr.LoadIssue(db.DefaultContext))
|
||
|
assert.NoError(t, pr.LoadAttributes(db.DefaultContext))
|
||
5 years ago
|
// simulate fork deletion
|
||
|
pr.HeadRepo = nil
|
||
|
pr.HeadRepoID = 100000
|
||
3 years ago
|
apiPullRequest = ToAPIPullRequest(git.DefaultContext, pr, nil)
|
||
5 years ago
|
assert.NotNil(t, apiPullRequest)
|
||
|
assert.Nil(t, apiPullRequest.Head.Repository)
|
||
|
assert.EqualValues(t, -1, apiPullRequest.Head.RepoID)
|
||
5 years ago
|
}
|