From 6d2f6453637cc4335dca74f1afad5a80c6d34282 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Thu, 25 Apr 2024 00:08:53 +0200 Subject: [PATCH] tests: Let CreateDeclarativeRepoWithOptions create a Wiki too Add a new member to `DeclarativeRepoOptions`: `WikiBranch`. If specified, create a Wiki with the given branch, and a single "Home" page. This will be used by an upcoming test. Signed-off-by: Gergely Nagy --- tests/integration/integration_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/integration/integration_test.go b/tests/integration/integration_test.go index 7a373c74ee..61a243e52f 100644 --- a/tests/integration/integration_test.go +++ b/tests/integration/integration_test.go @@ -46,6 +46,7 @@ import ( repo_service "code.gitea.io/gitea/services/repository" files_service "code.gitea.io/gitea/services/repository/files" user_service "code.gitea.io/gitea/services/user" + wiki_service "code.gitea.io/gitea/services/wiki" "code.gitea.io/gitea/tests" "github.com/PuerkitoBio/goquery" @@ -658,6 +659,7 @@ type DeclarativeRepoOptions struct { EnabledUnits optional.Option[[]unit_model.Type] DisabledUnits optional.Option[[]unit_model.Type] Files optional.Option[[]*files_service.ChangeRepoFile] + WikiBranch optional.Option[string] } func CreateDeclarativeRepoWithOptions(t *testing.T, owner *user_model.User, opts DeclarativeRepoOptions) (*repo_model.Repository, string, func()) { @@ -734,6 +736,22 @@ func CreateDeclarativeRepoWithOptions(t *testing.T, owner *user_model.User, opts sha = resp.Commit.SHA } + // If there's a Wiki branch specified, create a wiki, and a default wiki page. + if opts.WikiBranch.Has() { + // Set the wiki branch in the database first + repo.WikiBranch = opts.WikiBranch.Value() + err := repo_model.UpdateRepositoryCols(db.DefaultContext, repo, "wiki_branch") + assert.NoError(t, err) + + // Initialize the wiki + err = wiki_service.InitWiki(db.DefaultContext, repo) + assert.NoError(t, err) + + // Add a new wiki page + err = wiki_service.AddWikiPage(db.DefaultContext, owner, repo, "Home", "Welcome to the wiki!", "Add a Home page") + assert.NoError(t, err) + } + // Return the repo, the top commit, and a defer-able function to delete the // repo. return repo, sha, func() {