mirror of
https://codeberg.org/forgejo/forgejo
synced 2024-12-01 14:26:10 +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
6f35a5ab90
commit
f83ae0fad2
|
@ -660,6 +660,7 @@ type DeclarativeRepoOptions struct {
|
||||||
DisabledUnits optional.Option[[]unit_model.Type]
|
DisabledUnits optional.Option[[]unit_model.Type]
|
||||||
Files optional.Option[[]*files_service.ChangeRepoFile]
|
Files optional.Option[[]*files_service.ChangeRepoFile]
|
||||||
WikiBranch optional.Option[string]
|
WikiBranch optional.Option[string]
|
||||||
|
AutoInit optional.Option[bool]
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateDeclarativeRepoWithOptions(t *testing.T, owner *user_model.User, opts DeclarativeRepoOptions) (*repo_model.Repository, string, func()) {
|
func CreateDeclarativeRepoWithOptions(t *testing.T, owner *user_model.User, opts DeclarativeRepoOptions) (*repo_model.Repository, string, func()) {
|
||||||
|
@ -674,11 +675,18 @@ func CreateDeclarativeRepoWithOptions(t *testing.T, owner *user_model.User, opts
|
||||||
repoName = gouuid.NewString()
|
repoName = gouuid.NewString()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var autoInit bool
|
||||||
|
if opts.AutoInit.Has() {
|
||||||
|
autoInit = opts.AutoInit.Value()
|
||||||
|
} else {
|
||||||
|
autoInit = true
|
||||||
|
}
|
||||||
|
|
||||||
// Create the repository
|
// Create the repository
|
||||||
repo, err := repo_service.CreateRepository(db.DefaultContext, owner, owner, repo_service.CreateRepoOptions{
|
repo, err := repo_service.CreateRepository(db.DefaultContext, owner, owner, repo_service.CreateRepoOptions{
|
||||||
Name: repoName,
|
Name: repoName,
|
||||||
Description: "Temporary Repo",
|
Description: "Temporary Repo",
|
||||||
AutoInit: true,
|
AutoInit: autoInit,
|
||||||
Gitignores: "",
|
Gitignores: "",
|
||||||
License: "WTFPL",
|
License: "WTFPL",
|
||||||
Readme: "Default",
|
Readme: "Default",
|
||||||
|
@ -710,6 +718,7 @@ func CreateDeclarativeRepoWithOptions(t *testing.T, owner *user_model.User, opts
|
||||||
// Add files, if any.
|
// Add files, if any.
|
||||||
var sha string
|
var sha string
|
||||||
if opts.Files.Has() {
|
if opts.Files.Has() {
|
||||||
|
assert.True(t, autoInit, "Files cannot be specified if AutoInit is disabled")
|
||||||
files := opts.Files.Value()
|
files := opts.Files.Value()
|
||||||
|
|
||||||
resp, err := files_service.ChangeRepoFiles(git.DefaultContext, repo, owner, &files_service.ChangeRepoFilesOptions{
|
resp, err := files_service.ChangeRepoFiles(git.DefaultContext, repo, owner, &files_service.ChangeRepoFilesOptions{
|
||||||
|
|
Loading…
Reference in a new issue