Improve git test (#7086)
* Ensure that the lfs files are created with a different prefix * Reduce the replication in git_test.go
This commit is contained in:
@ -5,11 +5,14 @@
|
|||||||
package integrations
|
package integrations
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"code.gitea.io/gitea/models"
|
||||||
|
"code.gitea.io/gitea/modules/auth"
|
||||||
api "code.gitea.io/gitea/modules/structs"
|
api "code.gitea.io/gitea/modules/structs"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
@ -150,3 +153,42 @@ func doAPICreateDeployKey(ctx APITestContext, keyname, keyFile string, readOnly
|
|||||||
ctx.Session.MakeRequest(t, req, http.StatusCreated)
|
ctx.Session.MakeRequest(t, req, http.StatusCreated)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func doAPICreatePullRequest(ctx APITestContext, owner, repo, baseBranch, headBranch string) func(*testing.T) (api.PullRequest, error) {
|
||||||
|
return func(t *testing.T) (api.PullRequest, error) {
|
||||||
|
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/pulls?token=%s",
|
||||||
|
owner, repo, ctx.Token)
|
||||||
|
req := NewRequestWithJSON(t, http.MethodPost, urlStr, &api.CreatePullRequestOption{
|
||||||
|
Head: headBranch,
|
||||||
|
Base: baseBranch,
|
||||||
|
Title: fmt.Sprintf("create a pr from %s to %s", headBranch, baseBranch),
|
||||||
|
})
|
||||||
|
|
||||||
|
expected := 201
|
||||||
|
if ctx.ExpectedCode != 0 {
|
||||||
|
expected = ctx.ExpectedCode
|
||||||
|
}
|
||||||
|
resp := ctx.Session.MakeRequest(t, req, expected)
|
||||||
|
decoder := json.NewDecoder(resp.Body)
|
||||||
|
pr := api.PullRequest{}
|
||||||
|
err := decoder.Decode(&pr)
|
||||||
|
return pr, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func doAPIMergePullRequest(ctx APITestContext, owner, repo string, index int64) func(*testing.T) {
|
||||||
|
return func(t *testing.T) {
|
||||||
|
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/merge?token=%s",
|
||||||
|
owner, repo, index, ctx.Token)
|
||||||
|
req := NewRequestWithJSON(t, http.MethodPost, urlStr, &auth.MergePullRequestForm{
|
||||||
|
MergeMessageField: "doAPIMergePullRequest Merge",
|
||||||
|
Do: string(models.MergeStyleMerge),
|
||||||
|
})
|
||||||
|
|
||||||
|
if ctx.ExpectedCode != 0 {
|
||||||
|
ctx.Session.MakeRequest(t, req, ctx.ExpectedCode)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ctx.Session.MakeRequest(t, req, 200)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -112,16 +112,44 @@ func doGitAddRemote(dstPath, remoteName string, u *url.URL) func(*testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func doGitPushTestRepository(dstPath, remoteName, branch string) func(*testing.T) {
|
func doGitPushTestRepository(dstPath string, args ...string) func(*testing.T) {
|
||||||
return func(t *testing.T) {
|
return func(t *testing.T) {
|
||||||
_, err := git.NewCommand("push", "-u", remoteName, branch).RunInDir(dstPath)
|
_, err := git.NewCommand(append([]string{"push", "-u"}, args...)...).RunInDir(dstPath)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func doGitPushTestRepositoryFail(dstPath, remoteName, branch string) func(*testing.T) {
|
func doGitPushTestRepositoryFail(dstPath string, args ...string) func(*testing.T) {
|
||||||
return func(t *testing.T) {
|
return func(t *testing.T) {
|
||||||
_, err := git.NewCommand("push", "-u", remoteName, branch).RunInDir(dstPath)
|
_, err := git.NewCommand(append([]string{"push"}, args...)...).RunInDir(dstPath)
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func doGitCreateBranch(dstPath, branch string) func(*testing.T) {
|
||||||
|
return func(t *testing.T) {
|
||||||
|
_, err := git.NewCommand("checkout", "-b", branch).RunInDir(dstPath)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func doGitCheckoutBranch(dstPath string, args ...string) func(*testing.T) {
|
||||||
|
return func(t *testing.T) {
|
||||||
|
_, err := git.NewCommand(append([]string{"checkout"}, args...)...).RunInDir(dstPath)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func doGitMerge(dstPath string, args ...string) func(*testing.T) {
|
||||||
|
return func(t *testing.T) {
|
||||||
|
_, err := git.NewCommand(append([]string{"merge"}, args...)...).RunInDir(dstPath)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func doGitPull(dstPath string, args ...string) func(*testing.T) {
|
||||||
|
return func(t *testing.T) {
|
||||||
|
_, err := git.NewCommand(append([]string{"pull"}, args...)...).RunInDir(dstPath)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user