mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-26 01:14:10 -05:00
d97e36f6d7
includes: - easier repo declaration for playwright tests by @Gusted - full backend build for pushing Git repos by @Gusted - playwright testing (which fails with the current diff algorithm, but passes with the new) - disable eslint rule for conditional expect, because it defeats the purpose (working around it would result in much more complex test code in our cases)
83 lines
2.3 KiB
Go
83 lines
2.3 KiB
Go
// Copyright 2024 The Forgejo Authors. All rights reserved.
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
package e2e
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
unit_model "code.gitea.io/gitea/models/unit"
|
|
"code.gitea.io/gitea/models/unittest"
|
|
user_model "code.gitea.io/gitea/models/user"
|
|
"code.gitea.io/gitea/modules/git"
|
|
files_service "code.gitea.io/gitea/services/repository/files"
|
|
"code.gitea.io/gitea/tests"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
type FileChanges [][]string
|
|
|
|
// put your Git repo declarations in here
|
|
// feel free to amend the helper function below or use the raw variant directly
|
|
func DeclareGitRepos(t *testing.T) func() {
|
|
var cleanupFunctions []func()
|
|
cleanupFunctions = append(cleanupFunctions, newRepo(t, 2, "diff-test", FileChanges{
|
|
{"testfile", "hello", "hallo", "hola", "native", "ubuntu-latest", "- runs-on: ubuntu-latest", "- runs-on: debian-latest"},
|
|
}))
|
|
|
|
return func() {
|
|
for _, cleanup := range cleanupFunctions {
|
|
cleanup()
|
|
}
|
|
}
|
|
}
|
|
|
|
func newRepo(t *testing.T, userID int64, repoName string, fileChanges FileChanges) func() {
|
|
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: userID})
|
|
somerepo, _, cleanupFunc := tests.CreateDeclarativeRepo(t, user, repoName,
|
|
[]unit_model.Type{unit_model.TypeCode, unit_model.TypeIssues}, nil,
|
|
nil,
|
|
)
|
|
|
|
for _, file := range fileChanges {
|
|
changeLen := len(file)
|
|
for i := 1; i < changeLen; i++ {
|
|
operation := "create"
|
|
if i != 1 {
|
|
operation = "update"
|
|
}
|
|
resp, err := files_service.ChangeRepoFiles(git.DefaultContext, somerepo, user, &files_service.ChangeRepoFilesOptions{
|
|
Files: []*files_service.ChangeRepoFile{{
|
|
Operation: operation,
|
|
TreePath: file[0],
|
|
ContentReader: strings.NewReader(file[i]),
|
|
}},
|
|
Message: fmt.Sprintf("Patch: %s-%s", file[0], strconv.Itoa(i)),
|
|
OldBranch: "main",
|
|
NewBranch: "main",
|
|
Author: &files_service.IdentityOptions{
|
|
Name: user.Name,
|
|
Email: user.Email,
|
|
},
|
|
Committer: &files_service.IdentityOptions{
|
|
Name: user.Name,
|
|
Email: user.Email,
|
|
},
|
|
Dates: &files_service.CommitDateOptions{
|
|
Author: time.Now(),
|
|
Committer: time.Now(),
|
|
},
|
|
})
|
|
require.NoError(t, err)
|
|
assert.NotEmpty(t, resp)
|
|
}
|
|
}
|
|
|
|
return cleanupFunc
|
|
}
|