mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-25 14:35:40 +00:00
[TESTS] Convert more tests to CreateDeclarativeRepo
These tests originate from Gitea, so may cause conflicts in the longer run. But they use the same pattern, so transitioning them to the helper is hopefully a benefit that offsets the risk. Signed-off-by: Gergely Nagy <forgejo@gergo.csillger.hu> (cherry picked from commit2d475af494
) (cherry picked from commita99c17729c
)
This commit is contained in:
parent
48d752c630
commit
fdda432d1e
|
@ -11,9 +11,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
actions_model "code.gitea.io/gitea/models/actions"
|
actions_model "code.gitea.io/gitea/models/actions"
|
||||||
"code.gitea.io/gitea/models/db"
|
|
||||||
issues_model "code.gitea.io/gitea/models/issues"
|
issues_model "code.gitea.io/gitea/models/issues"
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
|
||||||
unit_model "code.gitea.io/gitea/models/unit"
|
unit_model "code.gitea.io/gitea/models/unit"
|
||||||
"code.gitea.io/gitea/models/unittest"
|
"code.gitea.io/gitea/models/unittest"
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
|
@ -33,25 +31,10 @@ func TestPullRequestTargetEvent(t *testing.T) {
|
||||||
org3 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 3}) // owner of the forked repo
|
org3 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 3}) // owner of the forked repo
|
||||||
|
|
||||||
// create the base repo
|
// create the base repo
|
||||||
baseRepo, err := repo_service.CreateRepository(db.DefaultContext, user2, user2, repo_service.CreateRepoOptions{
|
baseRepo, _, f := CreateDeclarativeRepo(t, user2, "repo-pull-request-target",
|
||||||
Name: "repo-pull-request-target",
|
[]unit_model.Type{unit_model.TypeActions}, nil, nil,
|
||||||
Description: "test pull-request-target event",
|
)
|
||||||
AutoInit: true,
|
defer f()
|
||||||
Gitignores: "Go",
|
|
||||||
License: "MIT",
|
|
||||||
Readme: "Default",
|
|
||||||
DefaultBranch: "main",
|
|
||||||
IsPrivate: false,
|
|
||||||
})
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.NotEmpty(t, baseRepo)
|
|
||||||
|
|
||||||
// enable actions
|
|
||||||
err = repo_model.UpdateRepositoryUnits(db.DefaultContext, baseRepo, []repo_model.RepoUnit{{
|
|
||||||
RepoID: baseRepo.ID,
|
|
||||||
Type: unit_model.TypeActions,
|
|
||||||
}}, nil)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
|
|
||||||
// create the forked repo
|
// create the forked repo
|
||||||
forkedRepo, err := repo_service.ForkRepository(git.DefaultContext, user2, org3, repo_service.ForkRepoOptions{
|
forkedRepo, err := repo_service.ForkRepository(git.DefaultContext, user2, org3, repo_service.ForkRepoOptions{
|
||||||
|
@ -202,53 +185,17 @@ func TestSkipCI(t *testing.T) {
|
||||||
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||||
|
|
||||||
// create the repo
|
// create the repo
|
||||||
repo, err := repo_service.CreateRepository(db.DefaultContext, user2, user2, repo_service.CreateRepoOptions{
|
repo, _, f := CreateDeclarativeRepo(t, user2, "skip-ci",
|
||||||
Name: "skip-ci",
|
[]unit_model.Type{unit_model.TypeActions}, nil,
|
||||||
Description: "test skip ci functionality",
|
[]*files_service.ChangeRepoFile{
|
||||||
AutoInit: true,
|
|
||||||
Gitignores: "Go",
|
|
||||||
License: "MIT",
|
|
||||||
Readme: "Default",
|
|
||||||
DefaultBranch: "main",
|
|
||||||
IsPrivate: false,
|
|
||||||
})
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.NotEmpty(t, repo)
|
|
||||||
|
|
||||||
// enable actions
|
|
||||||
err = repo_model.UpdateRepositoryUnits(db.DefaultContext, repo, []repo_model.RepoUnit{{
|
|
||||||
RepoID: repo.ID,
|
|
||||||
Type: unit_model.TypeActions,
|
|
||||||
}}, nil)
|
|
||||||
assert.NoError(t, err)
|
|
||||||
|
|
||||||
// add workflow file to the repo
|
|
||||||
addWorkflowToBaseResp, err := files_service.ChangeRepoFiles(git.DefaultContext, repo, user2, &files_service.ChangeRepoFilesOptions{
|
|
||||||
Files: []*files_service.ChangeRepoFile{
|
|
||||||
{
|
{
|
||||||
Operation: "create",
|
Operation: "create",
|
||||||
TreePath: ".gitea/workflows/pr.yml",
|
TreePath: ".gitea/workflows/pr.yml",
|
||||||
ContentReader: strings.NewReader("name: test\non:\n push:\njobs:\n test:\n runs-on: ubuntu-latest\n steps:\n - run: echo helloworld\n"),
|
ContentReader: strings.NewReader("name: test\non:\n push:\njobs:\n test:\n runs-on: ubuntu-latest\n steps:\n - run: echo helloworld\n"),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Message: "add workflow",
|
)
|
||||||
OldBranch: "main",
|
defer f()
|
||||||
NewBranch: "main",
|
|
||||||
Author: &files_service.IdentityOptions{
|
|
||||||
Name: user2.Name,
|
|
||||||
Email: user2.Email,
|
|
||||||
},
|
|
||||||
Committer: &files_service.IdentityOptions{
|
|
||||||
Name: user2.Name,
|
|
||||||
Email: user2.Email,
|
|
||||||
},
|
|
||||||
Dates: &files_service.CommitDateOptions{
|
|
||||||
Author: time.Now(),
|
|
||||||
Committer: time.Now(),
|
|
||||||
},
|
|
||||||
})
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.NotEmpty(t, addWorkflowToBaseResp)
|
|
||||||
|
|
||||||
// a run has been created
|
// a run has been created
|
||||||
assert.Equal(t, 1, unittest.GetCount(t, &actions_model.ActionRun{RepoID: repo.ID}))
|
assert.Equal(t, 1, unittest.GetCount(t, &actions_model.ActionRun{RepoID: repo.ID}))
|
||||||
|
|
|
@ -30,7 +30,6 @@ import (
|
||||||
"code.gitea.io/gitea/modules/test"
|
"code.gitea.io/gitea/modules/test"
|
||||||
"code.gitea.io/gitea/modules/translation"
|
"code.gitea.io/gitea/modules/translation"
|
||||||
"code.gitea.io/gitea/services/pull"
|
"code.gitea.io/gitea/services/pull"
|
||||||
repo_service "code.gitea.io/gitea/services/repository"
|
|
||||||
files_service "code.gitea.io/gitea/services/repository/files"
|
files_service "code.gitea.io/gitea/services/repository/files"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
@ -370,18 +369,11 @@ func TestConflictChecking(t *testing.T) {
|
||||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||||
|
|
||||||
// Create new clean repo to test conflict checking.
|
// Create new clean repo to test conflict checking.
|
||||||
baseRepo, err := repo_service.CreateRepository(db.DefaultContext, user, user, repo_service.CreateRepoOptions{
|
baseRepo, _, f := CreateDeclarativeRepo(t, user, "conflict-checking", nil, nil, nil)
|
||||||
Name: "conflict-checking",
|
defer f()
|
||||||
Description: "Tempo repo",
|
|
||||||
AutoInit: true,
|
|
||||||
Readme: "Default",
|
|
||||||
DefaultBranch: "main",
|
|
||||||
})
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.NotEmpty(t, baseRepo)
|
|
||||||
|
|
||||||
// create a commit on new branch.
|
// create a commit on new branch.
|
||||||
_, err = files_service.ChangeRepoFiles(git.DefaultContext, baseRepo, user, &files_service.ChangeRepoFilesOptions{
|
_, err := files_service.ChangeRepoFiles(git.DefaultContext, baseRepo, user, &files_service.ChangeRepoFilesOptions{
|
||||||
Files: []*files_service.ChangeRepoFile{
|
Files: []*files_service.ChangeRepoFile{
|
||||||
{
|
{
|
||||||
Operation: "create",
|
Operation: "create",
|
||||||
|
|
|
@ -82,17 +82,7 @@ func TestAPIPullUpdateByRebase(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func createOutdatedPR(t *testing.T, actor, forkOrg *user_model.User) *issues_model.PullRequest {
|
func createOutdatedPR(t *testing.T, actor, forkOrg *user_model.User) *issues_model.PullRequest {
|
||||||
baseRepo, err := repo_service.CreateRepository(db.DefaultContext, actor, actor, repo_service.CreateRepoOptions{
|
baseRepo, _, _ := CreateDeclarativeRepo(t, actor, "repo-pr-update", nil, nil, nil)
|
||||||
Name: "repo-pr-update",
|
|
||||||
Description: "repo-tmp-pr-update description",
|
|
||||||
AutoInit: true,
|
|
||||||
Gitignores: "C,C++",
|
|
||||||
License: "MIT",
|
|
||||||
Readme: "Default",
|
|
||||||
IsPrivate: false,
|
|
||||||
})
|
|
||||||
assert.NoError(t, err)
|
|
||||||
assert.NotEmpty(t, baseRepo)
|
|
||||||
|
|
||||||
headRepo, err := repo_service.ForkRepository(git.DefaultContext, actor, forkOrg, repo_service.ForkRepoOptions{
|
headRepo, err := repo_service.ForkRepository(git.DefaultContext, actor, forkOrg, repo_service.ForkRepoOptions{
|
||||||
BaseRepo: baseRepo,
|
BaseRepo: baseRepo,
|
||||||
|
@ -112,8 +102,8 @@ func createOutdatedPR(t *testing.T, actor, forkOrg *user_model.User) *issues_mod
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Message: "Add File A",
|
Message: "Add File A",
|
||||||
OldBranch: "master",
|
OldBranch: "main",
|
||||||
NewBranch: "master",
|
NewBranch: "main",
|
||||||
Author: &files_service.IdentityOptions{
|
Author: &files_service.IdentityOptions{
|
||||||
Name: actor.Name,
|
Name: actor.Name,
|
||||||
Email: actor.Email,
|
Email: actor.Email,
|
||||||
|
@ -139,7 +129,7 @@ func createOutdatedPR(t *testing.T, actor, forkOrg *user_model.User) *issues_mod
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Message: "Add File on PR branch",
|
Message: "Add File on PR branch",
|
||||||
OldBranch: "master",
|
OldBranch: "main",
|
||||||
NewBranch: "newBranch",
|
NewBranch: "newBranch",
|
||||||
Author: &files_service.IdentityOptions{
|
Author: &files_service.IdentityOptions{
|
||||||
Name: actor.Name,
|
Name: actor.Name,
|
||||||
|
@ -168,7 +158,7 @@ func createOutdatedPR(t *testing.T, actor, forkOrg *user_model.User) *issues_mod
|
||||||
HeadRepoID: headRepo.ID,
|
HeadRepoID: headRepo.ID,
|
||||||
BaseRepoID: baseRepo.ID,
|
BaseRepoID: baseRepo.ID,
|
||||||
HeadBranch: "newBranch",
|
HeadBranch: "newBranch",
|
||||||
BaseBranch: "master",
|
BaseBranch: "main",
|
||||||
HeadRepo: headRepo,
|
HeadRepo: headRepo,
|
||||||
BaseRepo: baseRepo,
|
BaseRepo: baseRepo,
|
||||||
Type: issues_model.PullRequestGitea,
|
Type: issues_model.PullRequestGitea,
|
||||||
|
|
Loading…
Reference in a new issue