From 8cc5d5dc784b11b07b21daa6f46a29c263b94806 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Tue, 30 Apr 2024 01:35:40 +0200 Subject: [PATCH] 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 --- tests/integration/integration_test.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/integration/integration_test.go b/tests/integration/integration_test.go index f5b87231f3..f6daf0d146 100644 --- a/tests/integration/integration_test.go +++ b/tests/integration/integration_test.go @@ -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{