mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-23 19:11:58 +01:00
tests: Support creating a declarative repo without AutoInit
To be able to easily test cases where the repository does not have any code, where the git repo itself is completely uninitialized, lets support a case where the `AutoInit` property is false. For the sake of backwards compatibility, if the option is not set either way, it will default to `true`. Signed-off-by: Gergely Nagy <forgejo@gergo.csillger.hu>
This commit is contained in:
parent
632a274b8f
commit
8cc5d5dc78
1 changed files with 10 additions and 1 deletions
|
@ -692,6 +692,7 @@ type DeclarativeRepoOptions struct {
|
|||
DisabledUnits optional.Option[[]unit_model.Type]
|
||||
Files optional.Option[[]*files_service.ChangeRepoFile]
|
||||
WikiBranch optional.Option[string]
|
||||
AutoInit optional.Option[bool]
|
||||
}
|
||||
|
||||
func CreateDeclarativeRepoWithOptions(t *testing.T, owner *user_model.User, opts DeclarativeRepoOptions) (*repo_model.Repository, string, func()) {
|
||||
|
@ -706,11 +707,18 @@ func CreateDeclarativeRepoWithOptions(t *testing.T, owner *user_model.User, opts
|
|||
repoName = gouuid.NewString()
|
||||
}
|
||||
|
||||
var autoInit bool
|
||||
if opts.AutoInit.Has() {
|
||||
autoInit = opts.AutoInit.Value()
|
||||
} else {
|
||||
autoInit = true
|
||||
}
|
||||
|
||||
// Create the repository
|
||||
repo, err := repo_service.CreateRepository(db.DefaultContext, owner, owner, repo_service.CreateRepoOptions{
|
||||
Name: repoName,
|
||||
Description: "Temporary Repo",
|
||||
AutoInit: true,
|
||||
AutoInit: autoInit,
|
||||
Gitignores: "",
|
||||
License: "WTFPL",
|
||||
Readme: "Default",
|
||||
|
@ -742,6 +750,7 @@ func CreateDeclarativeRepoWithOptions(t *testing.T, owner *user_model.User, opts
|
|||
// Add files, if any.
|
||||
var sha string
|
||||
if opts.Files.Has() {
|
||||
assert.True(t, autoInit, "Files cannot be specified if AutoInit is disabled")
|
||||
files := opts.Files.Value()
|
||||
|
||||
resp, err := files_service.ChangeRepoFiles(git.DefaultContext, repo, owner, &files_service.ChangeRepoFilesOptions{
|
||||
|
|
Loading…
Reference in a new issue