aboutsummaryrefslogtreecommitdiffstats
path: root/tests/integration
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2023-07-19 02:14:47 +0800
committerGitHub <noreply@github.com>2023-07-18 18:14:47 +0000
commit236c645bf16754ca9294545e71014a01a24ccfd8 (patch)
tree4ca9d8f93aca854d841a7379955e9653a8212546 /tests/integration
parent265a28802a6062d86964c9bfe1959437eaf69afb (diff)
downloadgitea-236c645bf16754ca9294545e71014a01a24ccfd8.tar.gz
gitea-236c645bf16754ca9294545e71014a01a24ccfd8.zip
Refactor "Content" for file uploading (#25851)
Before: the concept "Content string" is used everywhere. It has some problems: 1. Sometimes it means "base64 encoded content", sometimes it means "raw binary content" 2. It doesn't work with large files, eg: uploading a 1G LFS file would make Gitea process OOM This PR does the refactoring: use "ContentReader" / "ContentBase64" instead of "Content" This PR is not breaking because the key in API JSON is still "content": `` ContentBase64 string `json:"content"` ``
Diffstat (limited to 'tests/integration')
-rw-r--r--tests/integration/actions_trigger_test.go13
-rw-r--r--tests/integration/api_repo_file_create_test.go2
-rw-r--r--tests/integration/api_repo_file_helpers.go8
-rw-r--r--tests/integration/api_repo_file_update_test.go2
-rw-r--r--tests/integration/api_repo_files_change_test.go10
-rw-r--r--tests/integration/empty_repo_test.go2
-rw-r--r--tests/integration/gpg_git_test.go2
-rw-r--r--tests/integration/pull_merge_test.go12
-rw-r--r--tests/integration/pull_update_test.go13
-rw-r--r--tests/integration/repofiles_change_test.go15
10 files changed, 42 insertions, 37 deletions
diff --git a/tests/integration/actions_trigger_test.go b/tests/integration/actions_trigger_test.go
index bacf13e6c5..241d6172f7 100644
--- a/tests/integration/actions_trigger_test.go
+++ b/tests/integration/actions_trigger_test.go
@@ -5,6 +5,7 @@ package integration
import (
"net/url"
+ "strings"
"testing"
"time"
@@ -64,9 +65,9 @@ func TestPullRequestTargetEvent(t *testing.T) {
addWorkflowToBaseResp, err := files_service.ChangeRepoFiles(git.DefaultContext, baseRepo, user2, &files_service.ChangeRepoFilesOptions{
Files: []*files_service.ChangeRepoFile{
{
- Operation: "create",
- TreePath: ".gitea/workflows/pr.yml",
- Content: "name: test\non: pull_request_target\njobs:\n test:\n runs-on: ubuntu-latest\n steps:\n - run: echo helloworld\n",
+ Operation: "create",
+ TreePath: ".gitea/workflows/pr.yml",
+ ContentReader: strings.NewReader("name: test\non: pull_request_target\njobs:\n test:\n runs-on: ubuntu-latest\n steps:\n - run: echo helloworld\n"),
},
},
Message: "add workflow",
@@ -92,9 +93,9 @@ func TestPullRequestTargetEvent(t *testing.T) {
addFileToForkedResp, err := files_service.ChangeRepoFiles(git.DefaultContext, forkedRepo, user3, &files_service.ChangeRepoFilesOptions{
Files: []*files_service.ChangeRepoFile{
{
- Operation: "create",
- TreePath: "file_1.txt",
- Content: "file1",
+ Operation: "create",
+ TreePath: "file_1.txt",
+ ContentReader: strings.NewReader("file1"),
},
},
Message: "add file1",
diff --git a/tests/integration/api_repo_file_create_test.go b/tests/integration/api_repo_file_create_test.go
index cbc164891b..2433a68c31 100644
--- a/tests/integration/api_repo_file_create_test.go
+++ b/tests/integration/api_repo_file_create_test.go
@@ -46,7 +46,7 @@ func getCreateFileOptions() api.CreateFileOptions {
Committer: time.Unix(978307190, 0),
},
},
- Content: contentEncoded,
+ ContentBase64: contentEncoded,
}
}
diff --git a/tests/integration/api_repo_file_helpers.go b/tests/integration/api_repo_file_helpers.go
index 8e9b2bfecc..27e127fcc8 100644
--- a/tests/integration/api_repo_file_helpers.go
+++ b/tests/integration/api_repo_file_helpers.go
@@ -4,6 +4,8 @@
package integration
import (
+ "strings"
+
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
@@ -15,9 +17,9 @@ func createFileInBranch(user *user_model.User, repo *repo_model.Repository, tree
opts := &files_service.ChangeRepoFilesOptions{
Files: []*files_service.ChangeRepoFile{
{
- Operation: "create",
- TreePath: treePath,
- Content: content,
+ Operation: "create",
+ TreePath: treePath,
+ ContentReader: strings.NewReader(content),
},
},
OldBranch: branchName,
diff --git a/tests/integration/api_repo_file_update_test.go b/tests/integration/api_repo_file_update_test.go
index 5bcb531fc1..9a29ccbf5e 100644
--- a/tests/integration/api_repo_file_update_test.go
+++ b/tests/integration/api_repo_file_update_test.go
@@ -44,7 +44,7 @@ func getUpdateFileOptions() *api.UpdateFileOptions {
},
SHA: "103ff9234cefeee5ec5361d22b49fbb04d385885",
},
- Content: contentEncoded,
+ ContentBase64: contentEncoded,
}
}
diff --git a/tests/integration/api_repo_files_change_test.go b/tests/integration/api_repo_files_change_test.go
index 8599b12a7f..c79764a067 100644
--- a/tests/integration/api_repo_files_change_test.go
+++ b/tests/integration/api_repo_files_change_test.go
@@ -44,13 +44,13 @@ func getChangeFilesOptions() *api.ChangeFilesOptions {
},
Files: []*api.ChangeFileOperation{
{
- Operation: "create",
- Content: newContentEncoded,
+ Operation: "create",
+ ContentBase64: newContentEncoded,
},
{
- Operation: "update",
- Content: updateContentEncoded,
- SHA: "103ff9234cefeee5ec5361d22b49fbb04d385885",
+ Operation: "update",
+ ContentBase64: updateContentEncoded,
+ SHA: "103ff9234cefeee5ec5361d22b49fbb04d385885",
},
{
Operation: "delete",
diff --git a/tests/integration/empty_repo_test.go b/tests/integration/empty_repo_test.go
index d604391dab..78453f28a5 100644
--- a/tests/integration/empty_repo_test.go
+++ b/tests/integration/empty_repo_test.go
@@ -125,7 +125,7 @@ func TestEmptyRepoAddFileByAPI(t *testing.T) {
NewBranchName: "new_branch",
Message: "init",
},
- Content: base64.StdEncoding.EncodeToString([]byte("newly-added-api-file")),
+ ContentBase64: base64.StdEncoding.EncodeToString([]byte("newly-added-api-file")),
})
resp := MakeRequest(t, req, http.StatusCreated)
diff --git a/tests/integration/gpg_git_test.go b/tests/integration/gpg_git_test.go
index 5b49c91c59..10174b99fe 100644
--- a/tests/integration/gpg_git_test.go
+++ b/tests/integration/gpg_git_test.go
@@ -337,7 +337,7 @@ func crudActionCreateFile(t *testing.T, ctx APITestContext, user *user_model.Use
Email: user.Email,
},
},
- Content: base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("This is new text for %s", path))),
+ ContentBase64: base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("This is new text for %s", path))),
}, callback...)
}
diff --git a/tests/integration/pull_merge_test.go b/tests/integration/pull_merge_test.go
index 7b7c8864c7..f958c890fe 100644
--- a/tests/integration/pull_merge_test.go
+++ b/tests/integration/pull_merge_test.go
@@ -370,9 +370,9 @@ func TestConflictChecking(t *testing.T) {
_, err = files_service.ChangeRepoFiles(git.DefaultContext, baseRepo, user, &files_service.ChangeRepoFilesOptions{
Files: []*files_service.ChangeRepoFile{
{
- Operation: "create",
- TreePath: "important_file",
- Content: "Just a non-important file",
+ Operation: "create",
+ TreePath: "important_file",
+ ContentReader: strings.NewReader("Just a non-important file"),
},
},
Message: "Add a important file",
@@ -385,9 +385,9 @@ func TestConflictChecking(t *testing.T) {
_, err = files_service.ChangeRepoFiles(git.DefaultContext, baseRepo, user, &files_service.ChangeRepoFilesOptions{
Files: []*files_service.ChangeRepoFile{
{
- Operation: "create",
- TreePath: "important_file",
- Content: "Not the same content :P",
+ Operation: "create",
+ TreePath: "important_file",
+ ContentReader: strings.NewReader("Not the same content :P"),
},
},
Message: "Add a important file",
diff --git a/tests/integration/pull_update_test.go b/tests/integration/pull_update_test.go
index fa56cec485..80c55042db 100644
--- a/tests/integration/pull_update_test.go
+++ b/tests/integration/pull_update_test.go
@@ -6,6 +6,7 @@ package integration
import (
"net/http"
"net/url"
+ "strings"
"testing"
"time"
@@ -104,9 +105,9 @@ func createOutdatedPR(t *testing.T, actor, forkOrg *user_model.User) *issues_mod
_, err = files_service.ChangeRepoFiles(git.DefaultContext, baseRepo, actor, &files_service.ChangeRepoFilesOptions{
Files: []*files_service.ChangeRepoFile{
{
- Operation: "create",
- TreePath: "File_A",
- Content: "File A",
+ Operation: "create",
+ TreePath: "File_A",
+ ContentReader: strings.NewReader("File A"),
},
},
Message: "Add File A",
@@ -131,9 +132,9 @@ func createOutdatedPR(t *testing.T, actor, forkOrg *user_model.User) *issues_mod
_, err = files_service.ChangeRepoFiles(git.DefaultContext, headRepo, actor, &files_service.ChangeRepoFilesOptions{
Files: []*files_service.ChangeRepoFile{
{
- Operation: "create",
- TreePath: "File_B",
- Content: "File B",
+ Operation: "create",
+ TreePath: "File_B",
+ ContentReader: strings.NewReader("File B"),
},
},
Message: "Add File on PR branch",
diff --git a/tests/integration/repofiles_change_test.go b/tests/integration/repofiles_change_test.go
index c273d38188..765a44689a 100644
--- a/tests/integration/repofiles_change_test.go
+++ b/tests/integration/repofiles_change_test.go
@@ -6,6 +6,7 @@ package integration
import (
"net/url"
"path/filepath"
+ "strings"
"testing"
"time"
@@ -24,9 +25,9 @@ func getCreateRepoFilesOptions(repo *repo_model.Repository) *files_service.Chang
return &files_service.ChangeRepoFilesOptions{
Files: []*files_service.ChangeRepoFile{
{
- Operation: "create",
- TreePath: "new/file.txt",
- Content: "This is a NEW file",
+ Operation: "create",
+ TreePath: "new/file.txt",
+ ContentReader: strings.NewReader("This is a NEW file"),
},
},
OldBranch: repo.DefaultBranch,
@@ -41,10 +42,10 @@ func getUpdateRepoFilesOptions(repo *repo_model.Repository) *files_service.Chang
return &files_service.ChangeRepoFilesOptions{
Files: []*files_service.ChangeRepoFile{
{
- Operation: "update",
- TreePath: "README.md",
- SHA: "4b4851ad51df6a7d9f25c979345979eaeb5b349f",
- Content: "This is UPDATED content for the README file",
+ Operation: "update",
+ TreePath: "README.md",
+ SHA: "4b4851ad51df6a7d9f25c979345979eaeb5b349f",
+ ContentReader: strings.NewReader("This is UPDATED content for the README file"),
},
},
OldBranch: repo.DefaultBranch,