mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-29 10:57:44 +09:00 
			
		
		
		
	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 | ||||
|  | ||||
| import ( | ||||
| 	"encoding/json" | ||||
| 	"fmt" | ||||
| 	"io/ioutil" | ||||
| 	"net/http" | ||||
| 	"testing" | ||||
|  | ||||
| 	"code.gitea.io/gitea/models" | ||||
| 	"code.gitea.io/gitea/modules/auth" | ||||
| 	api "code.gitea.io/gitea/modules/structs" | ||||
| 	"github.com/stretchr/testify/assert" | ||||
| ) | ||||
| @@ -150,3 +153,42 @@ func doAPICreateDeployKey(ctx APITestContext, keyname, keyFile string, readOnly | ||||
| 		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) | ||||
| 	} | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user