mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-19 12:34:50 +02:00
Merge remote-tracking branch 'upstream/main' into limit-repo-size
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -13,18 +13,18 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestActionsArtifactUpload(t *testing.T) {
|
||||
type uploadArtifactResponse struct {
|
||||
FileContainerResourceURL string `json:"fileContainerResourceUrl"`
|
||||
}
|
||||
|
||||
type getUploadArtifactRequest struct {
|
||||
Type string
|
||||
Name string
|
||||
}
|
||||
|
||||
func TestActionsArtifactUploadSingleFile(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
|
||||
type uploadArtifactResponse struct {
|
||||
FileContainerResourceURL string `json:"fileContainerResourceUrl"`
|
||||
}
|
||||
|
||||
type getUploadArtifactRequest struct {
|
||||
Type string
|
||||
Name string
|
||||
}
|
||||
|
||||
// acquire artifact upload url
|
||||
req := NewRequestWithJSON(t, "POST", "/api/actions_pipeline/_apis/pipelines/workflows/791/artifacts", getUploadArtifactRequest{
|
||||
Type: "actions_storage",
|
||||
@@ -52,32 +52,33 @@ func TestActionsArtifactUpload(t *testing.T) {
|
||||
t.Logf("Create artifact confirm")
|
||||
|
||||
// confirm artifact upload
|
||||
req = NewRequest(t, "PATCH", "/api/actions_pipeline/_apis/pipelines/workflows/791/artifacts")
|
||||
req = NewRequest(t, "PATCH", "/api/actions_pipeline/_apis/pipelines/workflows/791/artifacts?artifactName=artifact")
|
||||
req = addTokenAuthHeader(req, "Bearer 8061e833a55f6fc0157c98b883e91fcfeeb1a71a")
|
||||
MakeRequest(t, req, http.StatusOK)
|
||||
}
|
||||
|
||||
func TestActionsArtifactUploadNotExist(t *testing.T) {
|
||||
func TestActionsArtifactUploadInvalidHash(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
|
||||
// artifact id 54321 not exist
|
||||
url := "/api/actions_pipeline/_apis/pipelines/workflows/791/artifacts/54321/upload?itemPath=artifact/abc.txt"
|
||||
url := "/api/actions_pipeline/_apis/pipelines/workflows/791/artifacts/8e5b948a454515dbabfc7eb718ddddddd/upload?itemPath=artifact/abc.txt"
|
||||
body := strings.Repeat("A", 1024)
|
||||
req := NewRequestWithBody(t, "PUT", url, strings.NewReader(body))
|
||||
req = addTokenAuthHeader(req, "Bearer 8061e833a55f6fc0157c98b883e91fcfeeb1a71a")
|
||||
req.Header.Add("Content-Range", "bytes 0-1023/1024")
|
||||
req.Header.Add("x-tfs-filelength", "1024")
|
||||
req.Header.Add("x-actions-results-md5", "1HsSe8LeLWh93ILaw1TEFQ==") // base64(md5(body))
|
||||
MakeRequest(t, req, http.StatusNotFound)
|
||||
resp := MakeRequest(t, req, http.StatusBadRequest)
|
||||
assert.Contains(t, resp.Body.String(), "Invalid artifact hash")
|
||||
}
|
||||
|
||||
func TestActionsArtifactConfirmUpload(t *testing.T) {
|
||||
func TestActionsArtifactConfirmUploadWithoutName(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
|
||||
req := NewRequest(t, "PATCH", "/api/actions_pipeline/_apis/pipelines/workflows/791/artifacts")
|
||||
req = addTokenAuthHeader(req, "Bearer 8061e833a55f6fc0157c98b883e91fcfeeb1a71a")
|
||||
resp := MakeRequest(t, req, http.StatusOK)
|
||||
assert.Contains(t, resp.Body.String(), "success")
|
||||
resp := MakeRequest(t, req, http.StatusBadRequest)
|
||||
assert.Contains(t, resp.Body.String(), "artifact name is empty")
|
||||
}
|
||||
|
||||
func TestActionsArtifactUploadWithoutToken(t *testing.T) {
|
||||
@@ -87,20 +88,28 @@ func TestActionsArtifactUploadWithoutToken(t *testing.T) {
|
||||
MakeRequest(t, req, http.StatusUnauthorized)
|
||||
}
|
||||
|
||||
type (
|
||||
listArtifactsResponseItem struct {
|
||||
Name string `json:"name"`
|
||||
FileContainerResourceURL string `json:"fileContainerResourceUrl"`
|
||||
}
|
||||
listArtifactsResponse struct {
|
||||
Count int64 `json:"count"`
|
||||
Value []listArtifactsResponseItem `json:"value"`
|
||||
}
|
||||
downloadArtifactResponseItem struct {
|
||||
Path string `json:"path"`
|
||||
ItemType string `json:"itemType"`
|
||||
ContentLocation string `json:"contentLocation"`
|
||||
}
|
||||
downloadArtifactResponse struct {
|
||||
Value []downloadArtifactResponseItem `json:"value"`
|
||||
}
|
||||
)
|
||||
|
||||
func TestActionsArtifactDownload(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
|
||||
type (
|
||||
listArtifactsResponseItem struct {
|
||||
Name string `json:"name"`
|
||||
FileContainerResourceURL string `json:"fileContainerResourceUrl"`
|
||||
}
|
||||
listArtifactsResponse struct {
|
||||
Count int64 `json:"count"`
|
||||
Value []listArtifactsResponseItem `json:"value"`
|
||||
}
|
||||
)
|
||||
|
||||
req := NewRequest(t, "GET", "/api/actions_pipeline/_apis/pipelines/workflows/791/artifacts")
|
||||
req = addTokenAuthHeader(req, "Bearer 8061e833a55f6fc0157c98b883e91fcfeeb1a71a")
|
||||
resp := MakeRequest(t, req, http.StatusOK)
|
||||
@@ -110,19 +119,8 @@ func TestActionsArtifactDownload(t *testing.T) {
|
||||
assert.Equal(t, "artifact", listResp.Value[0].Name)
|
||||
assert.Contains(t, listResp.Value[0].FileContainerResourceURL, "/api/actions_pipeline/_apis/pipelines/workflows/791/artifacts")
|
||||
|
||||
type (
|
||||
downloadArtifactResponseItem struct {
|
||||
Path string `json:"path"`
|
||||
ItemType string `json:"itemType"`
|
||||
ContentLocation string `json:"contentLocation"`
|
||||
}
|
||||
downloadArtifactResponse struct {
|
||||
Value []downloadArtifactResponseItem `json:"value"`
|
||||
}
|
||||
)
|
||||
|
||||
idx := strings.Index(listResp.Value[0].FileContainerResourceURL, "/api/actions_pipeline/_apis/pipelines/")
|
||||
url := listResp.Value[0].FileContainerResourceURL[idx+1:]
|
||||
url := listResp.Value[0].FileContainerResourceURL[idx+1:] + "?itemPath=artifact"
|
||||
req = NewRequest(t, "GET", url)
|
||||
req = addTokenAuthHeader(req, "Bearer 8061e833a55f6fc0157c98b883e91fcfeeb1a71a")
|
||||
resp = MakeRequest(t, req, http.StatusOK)
|
||||
@@ -141,3 +139,116 @@ func TestActionsArtifactDownload(t *testing.T) {
|
||||
body := strings.Repeat("A", 1024)
|
||||
assert.Equal(t, resp.Body.String(), body)
|
||||
}
|
||||
|
||||
func TestActionsArtifactUploadMultipleFile(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
|
||||
const testArtifactName = "multi-files"
|
||||
|
||||
// acquire artifact upload url
|
||||
req := NewRequestWithJSON(t, "POST", "/api/actions_pipeline/_apis/pipelines/workflows/791/artifacts", getUploadArtifactRequest{
|
||||
Type: "actions_storage",
|
||||
Name: testArtifactName,
|
||||
})
|
||||
req = addTokenAuthHeader(req, "Bearer 8061e833a55f6fc0157c98b883e91fcfeeb1a71a")
|
||||
resp := MakeRequest(t, req, http.StatusOK)
|
||||
var uploadResp uploadArtifactResponse
|
||||
DecodeJSON(t, resp, &uploadResp)
|
||||
assert.Contains(t, uploadResp.FileContainerResourceURL, "/api/actions_pipeline/_apis/pipelines/workflows/791/artifacts")
|
||||
|
||||
type uploadingFile struct {
|
||||
Path string
|
||||
Content string
|
||||
MD5 string
|
||||
}
|
||||
|
||||
files := []uploadingFile{
|
||||
{
|
||||
Path: "abc.txt",
|
||||
Content: strings.Repeat("A", 1024),
|
||||
MD5: "1HsSe8LeLWh93ILaw1TEFQ==",
|
||||
},
|
||||
{
|
||||
Path: "xyz/def.txt",
|
||||
Content: strings.Repeat("B", 1024),
|
||||
MD5: "6fgADK/7zjadf+6cB9Q1CQ==",
|
||||
},
|
||||
}
|
||||
|
||||
for _, f := range files {
|
||||
// get upload url
|
||||
idx := strings.Index(uploadResp.FileContainerResourceURL, "/api/actions_pipeline/_apis/pipelines/")
|
||||
url := uploadResp.FileContainerResourceURL[idx:] + "?itemPath=" + testArtifactName + "/" + f.Path
|
||||
|
||||
// upload artifact chunk
|
||||
req = NewRequestWithBody(t, "PUT", url, strings.NewReader(f.Content))
|
||||
req = addTokenAuthHeader(req, "Bearer 8061e833a55f6fc0157c98b883e91fcfeeb1a71a")
|
||||
req.Header.Add("Content-Range", "bytes 0-1023/1024")
|
||||
req.Header.Add("x-tfs-filelength", "1024")
|
||||
req.Header.Add("x-actions-results-md5", f.MD5) // base64(md5(body))
|
||||
MakeRequest(t, req, http.StatusOK)
|
||||
}
|
||||
|
||||
t.Logf("Create artifact confirm")
|
||||
|
||||
// confirm artifact upload
|
||||
req = NewRequest(t, "PATCH", "/api/actions_pipeline/_apis/pipelines/workflows/791/artifacts?artifactName="+testArtifactName)
|
||||
req = addTokenAuthHeader(req, "Bearer 8061e833a55f6fc0157c98b883e91fcfeeb1a71a")
|
||||
MakeRequest(t, req, http.StatusOK)
|
||||
}
|
||||
|
||||
func TestActionsArtifactDownloadMultiFiles(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
|
||||
const testArtifactName = "multi-files"
|
||||
|
||||
req := NewRequest(t, "GET", "/api/actions_pipeline/_apis/pipelines/workflows/791/artifacts")
|
||||
req = addTokenAuthHeader(req, "Bearer 8061e833a55f6fc0157c98b883e91fcfeeb1a71a")
|
||||
resp := MakeRequest(t, req, http.StatusOK)
|
||||
var listResp listArtifactsResponse
|
||||
DecodeJSON(t, resp, &listResp)
|
||||
assert.Equal(t, int64(2), listResp.Count)
|
||||
|
||||
var fileContainerResourceURL string
|
||||
for _, v := range listResp.Value {
|
||||
if v.Name == testArtifactName {
|
||||
fileContainerResourceURL = v.FileContainerResourceURL
|
||||
break
|
||||
}
|
||||
}
|
||||
assert.Contains(t, fileContainerResourceURL, "/api/actions_pipeline/_apis/pipelines/workflows/791/artifacts")
|
||||
|
||||
idx := strings.Index(fileContainerResourceURL, "/api/actions_pipeline/_apis/pipelines/")
|
||||
url := fileContainerResourceURL[idx+1:] + "?itemPath=" + testArtifactName
|
||||
req = NewRequest(t, "GET", url)
|
||||
req = addTokenAuthHeader(req, "Bearer 8061e833a55f6fc0157c98b883e91fcfeeb1a71a")
|
||||
resp = MakeRequest(t, req, http.StatusOK)
|
||||
var downloadResp downloadArtifactResponse
|
||||
DecodeJSON(t, resp, &downloadResp)
|
||||
assert.Len(t, downloadResp.Value, 2)
|
||||
|
||||
downloads := [][]string{{"multi-files/abc.txt", "A"}, {"multi-files/xyz/def.txt", "B"}}
|
||||
for _, v := range downloadResp.Value {
|
||||
var bodyChar string
|
||||
var path string
|
||||
for _, d := range downloads {
|
||||
if v.Path == d[0] {
|
||||
path = d[0]
|
||||
bodyChar = d[1]
|
||||
break
|
||||
}
|
||||
}
|
||||
value := v
|
||||
assert.Equal(t, path, value.Path)
|
||||
assert.Equal(t, "file", value.ItemType)
|
||||
assert.Contains(t, value.ContentLocation, "/api/actions_pipeline/_apis/pipelines/workflows/791/artifacts")
|
||||
|
||||
idx = strings.Index(value.ContentLocation, "/api/actions_pipeline/_apis/pipelines/")
|
||||
url = value.ContentLocation[idx:]
|
||||
req = NewRequest(t, "GET", url)
|
||||
req = addTokenAuthHeader(req, "Bearer 8061e833a55f6fc0157c98b883e91fcfeeb1a71a")
|
||||
resp = MakeRequest(t, req, http.StatusOK)
|
||||
body := strings.Repeat(bodyChar, 1024)
|
||||
assert.Equal(t, resp.Body.String(), body)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,15 +196,15 @@ gpgkey=%sapi/packages/%s/rpm/repository.key`, user.Name, user.Name, setting.AppN
|
||||
switch d.Type {
|
||||
case "primary":
|
||||
assert.EqualValues(t, 718, d.Size)
|
||||
assert.EqualValues(t, 1731, d.OpenSize)
|
||||
assert.EqualValues(t, 1729, d.OpenSize)
|
||||
assert.Equal(t, "repodata/primary.xml.gz", d.Location.Href)
|
||||
case "filelists":
|
||||
assert.EqualValues(t, 258, d.Size)
|
||||
assert.EqualValues(t, 328, d.OpenSize)
|
||||
assert.EqualValues(t, 257, d.Size)
|
||||
assert.EqualValues(t, 326, d.OpenSize)
|
||||
assert.Equal(t, "repodata/filelists.xml.gz", d.Location.Href)
|
||||
case "other":
|
||||
assert.EqualValues(t, 308, d.Size)
|
||||
assert.EqualValues(t, 396, d.OpenSize)
|
||||
assert.EqualValues(t, 306, d.Size)
|
||||
assert.EqualValues(t, 394, d.OpenSize)
|
||||
assert.Equal(t, "repodata/other.xml.gz", d.Location.Href)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ func getCreateFileOptions() api.CreateFileOptions {
|
||||
Committer: time.Unix(978307190, 0),
|
||||
},
|
||||
},
|
||||
Content: contentEncoded,
|
||||
ContentBase64: contentEncoded,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -44,7 +44,7 @@ func getUpdateFileOptions() *api.UpdateFileOptions {
|
||||
},
|
||||
SHA: "103ff9234cefeee5ec5361d22b49fbb04d385885",
|
||||
},
|
||||
Content: contentEncoded,
|
||||
ContentBase64: contentEncoded,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -226,45 +226,20 @@ func TestLDAPUserSync(t *testing.T) {
|
||||
addAuthSourceLDAP(t, "", "")
|
||||
auth.SyncExternalUsers(context.Background(), true)
|
||||
|
||||
session := loginUser(t, "user1")
|
||||
// Check if users exists
|
||||
for _, u := range gitLDAPUsers {
|
||||
req := NewRequest(t, "GET", "/admin/users?q="+u.UserName)
|
||||
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||
|
||||
tr := htmlDoc.doc.Find("table.table tbody tr")
|
||||
if !assert.True(t, tr.Length() == 1) {
|
||||
continue
|
||||
}
|
||||
tds := tr.Find("td")
|
||||
if !assert.True(t, tds.Length() > 0) {
|
||||
continue
|
||||
}
|
||||
assert.Equal(t, u.UserName, strings.TrimSpace(tds.Find("td:nth-child(2) a").Text()))
|
||||
assert.Equal(t, u.Email, strings.TrimSpace(tds.Find("td:nth-child(3) span").Text()))
|
||||
if u.IsAdmin {
|
||||
assert.True(t, tds.Find("td:nth-child(5) svg").HasClass("octicon-check"))
|
||||
} else {
|
||||
assert.True(t, tds.Find("td:nth-child(5) svg").HasClass("octicon-x"))
|
||||
}
|
||||
if u.IsRestricted {
|
||||
assert.True(t, tds.Find("td:nth-child(6) svg").HasClass("octicon-check"))
|
||||
} else {
|
||||
assert.True(t, tds.Find("td:nth-child(6) svg").HasClass("octicon-x"))
|
||||
}
|
||||
for _, gitLDAPUser := range gitLDAPUsers {
|
||||
dbUser, err := user_model.GetUserByName(db.DefaultContext, gitLDAPUser.UserName)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, gitLDAPUser.UserName, dbUser.Name)
|
||||
assert.Equal(t, gitLDAPUser.Email, dbUser.Email)
|
||||
assert.Equal(t, gitLDAPUser.IsAdmin, dbUser.IsAdmin)
|
||||
assert.Equal(t, gitLDAPUser.IsRestricted, dbUser.IsRestricted)
|
||||
}
|
||||
|
||||
// Check if no users exist
|
||||
for _, u := range otherLDAPUsers {
|
||||
req := NewRequest(t, "GET", "/admin/users?q="+u.UserName)
|
||||
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||
|
||||
tr := htmlDoc.doc.Find("table.table tbody tr")
|
||||
assert.True(t, tr.Length() == 0)
|
||||
for _, otherLDAPUser := range otherLDAPUsers {
|
||||
_, err := user_model.GetUserByName(db.DefaultContext, otherLDAPUser.UserName)
|
||||
assert.True(t, user_model.IsErrUserNotExist(err))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,17 +5,15 @@ package integration
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"flag"
|
||||
"io"
|
||||
"net/url"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/cmd"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/modules/util"
|
||||
|
||||
"github.com/urfave/cli"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
func Test_CmdKeys(t *testing.T) {
|
||||
@@ -38,26 +36,18 @@ func Test_CmdKeys(t *testing.T) {
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
realStdout := os.Stdout // Backup Stdout
|
||||
r, w, _ := os.Pipe()
|
||||
os.Stdout = w
|
||||
|
||||
set := flag.NewFlagSet("keys", 0)
|
||||
_ = set.Parse(tt.args)
|
||||
context := cli.NewContext(&cli.App{Writer: os.Stdout}, set, nil)
|
||||
err := cmd.CmdKeys.Run(context)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("CmdKeys.Run() error = %v, wantErr %v", err, tt.wantErr)
|
||||
out := new(bytes.Buffer)
|
||||
app := cli.NewApp()
|
||||
app.Writer = out
|
||||
app.Commands = []*cli.Command{cmd.CmdKeys}
|
||||
cmd.CmdKeys.HideHelp = true
|
||||
err := app.Run(append([]string{"prog"}, tt.args...))
|
||||
if tt.wantErr {
|
||||
assert.Error(t, err)
|
||||
} else {
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
w.Close()
|
||||
var buf bytes.Buffer
|
||||
io.Copy(&buf, r)
|
||||
commandOutput := buf.String()
|
||||
if tt.expectedOutput != commandOutput {
|
||||
t.Errorf("expectedOutput: %#v, commandOutput: %#v", tt.expectedOutput, commandOutput)
|
||||
}
|
||||
// Restore stdout
|
||||
os.Stdout = realStdout
|
||||
assert.Equal(t, tt.expectedOutput, out.String())
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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...)
|
||||
}
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@ func TestLinksNoLogin(t *testing.T) {
|
||||
"/user2/repo1/projects/1",
|
||||
"/assets/img/404.png",
|
||||
"/assets/img/500.png",
|
||||
"/.well-known/security.txt",
|
||||
}
|
||||
|
||||
for _, link := range links {
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -52,7 +52,6 @@ func TestPullCreate_CommitStatus(t *testing.T) {
|
||||
api.CommitStatusPending,
|
||||
api.CommitStatusError,
|
||||
api.CommitStatusFailure,
|
||||
api.CommitStatusWarning,
|
||||
api.CommitStatusSuccess,
|
||||
}
|
||||
|
||||
@@ -61,7 +60,6 @@ func TestPullCreate_CommitStatus(t *testing.T) {
|
||||
api.CommitStatusSuccess: "octicon-check",
|
||||
api.CommitStatusError: "gitea-exclamation",
|
||||
api.CommitStatusFailure: "octicon-x",
|
||||
api.CommitStatusWarning: "gitea-exclamation",
|
||||
}
|
||||
|
||||
testCtx := NewAPITestContext(t, "user1", "repo1", auth_model.AccessTokenScopeWriteRepository)
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -110,7 +110,7 @@ func testRepoCommitsWithStatus(t *testing.T, resp, respOne *httptest.ResponseRec
|
||||
}
|
||||
|
||||
func TestRepoCommitsWithStatusPending(t *testing.T) {
|
||||
doTestRepoCommitWithStatus(t, "pending", "octicon-dot-fill", "grey")
|
||||
doTestRepoCommitWithStatus(t, "pending", "octicon-dot-fill", "yellow")
|
||||
}
|
||||
|
||||
func TestRepoCommitsWithStatusSuccess(t *testing.T) {
|
||||
@@ -125,14 +125,6 @@ func TestRepoCommitsWithStatusFailure(t *testing.T) {
|
||||
doTestRepoCommitWithStatus(t, "failure", "octicon-x", "red")
|
||||
}
|
||||
|
||||
func TestRepoCommitsWithStatusWarning(t *testing.T) {
|
||||
doTestRepoCommitWithStatus(t, "warning", "gitea-exclamation", "yellow")
|
||||
}
|
||||
|
||||
func TestRepoCommitsWithStatusRunning(t *testing.T) {
|
||||
doTestRepoCommitWithStatus(t, "running", "octicon-dot-fill", "yellow")
|
||||
}
|
||||
|
||||
func TestRepoCommitsStatusParallel(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user