From e934d0a3f3902dd86e96271c5c5dcc231acbdd13 Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Wed, 18 Jun 2025 10:56:30 +0200 Subject: [PATCH] fix(tests): TestInitInstructions must use forEachObjectFormat (#8220) Otherwise it [fails with older git versions](https://codeberg.org/forgejo-integration/forgejo/actions/runs/10341/jobs/1#jobstep-5-2706). ``` --- FAIL: TestInitInstructions (0.12s) testlogger.go:411: 2025/06/18 00:32:37 ...les/storage/local.go:33:NewLocalStorage() [I] Creating new Local Storage at /workspace/***/forgejo/tests/gitea-lfs-meta testlogger.go:411: 2025/06/18 00:32:37 ...eb/routing/logger.go:102:func1() [I] router: completed GET /user/login for test-mock:12345, 200 OK in 4.7ms @ auth/auth.go:145(auth.SignIn) testlogger.go:411: 2025/06/18 00:32:37 ...eb/routing/logger.go:102:func1() [I] router: completed POST /user/login for test-mock:12345, 303 See Other in 3.8ms @ auth/auth.go:179(auth.SignInPost) repo_test.go:1456: Error Trace: /workspace/***/forgejo/tests/test_utils.go:383 /workspace/***/forgejo/tests/integration/repo_test.go:1456 Error: Received unexpected error: initRepository: git.InitRepository: invalid object format: sha256 Test: TestInitInstructions ``` Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8220 Reviewed-by: Antonin Delpeuch Reviewed-by: oliverpool Co-authored-by: Earl Warren Co-committed-by: Earl Warren --- tests/integration/repo_test.go | 61 ++++++++++++---------------------- 1 file changed, 22 insertions(+), 39 deletions(-) diff --git a/tests/integration/repo_test.go b/tests/integration/repo_test.go index 19e8553bb2..b66726a3e6 100644 --- a/tests/integration/repo_test.go +++ b/tests/integration/repo_test.go @@ -1453,51 +1453,34 @@ func TestInitInstructions(t *testing.T) { user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}) session := loginUser(t, user.Name) - sha256Repo, _, f := tests.CreateDeclarativeRepoWithOptions(t, user, tests.DeclarativeRepoOptions{ - Name: optional.Some("sha256-instruction"), - AutoInit: optional.Some(false), - EnabledUnits: optional.Some([]unit_model.Type{unit_model.TypeCode}), - ObjectFormat: optional.Some("sha256"), - }) - defer f() - - sha1Repo, _, f := tests.CreateDeclarativeRepoWithOptions(t, user, tests.DeclarativeRepoOptions{ - Name: optional.Some("sha1-instruction"), - AutoInit: optional.Some(false), - EnabledUnits: optional.Some([]unit_model.Type{unit_model.TypeCode}), - ObjectFormat: optional.Some("sha1"), - }) - defer f() - - portMatcher := regexp.MustCompile(`localhost:\d+`) - - t.Run("sha256", func(t *testing.T) { + forEachObjectFormat(t, func(t *testing.T, objectFormat git.ObjectFormat) { defer tests.PrintCurrentTest(t)() + name := objectFormat.Name() + var init string + if name == "sha1" { + init = "git init" + } else { + init = fmt.Sprintf("git init --object-format=%s", name) + } - resp := session.MakeRequest(t, NewRequest(t, "GET", "/"+sha256Repo.FullName()), http.StatusOK) + repo, _, f := tests.CreateDeclarativeRepoWithOptions(t, user, tests.DeclarativeRepoOptions{ + Name: optional.Some(name + "-instruction"), + AutoInit: optional.Some(false), + EnabledUnits: optional.Some([]unit_model.Type{unit_model.TypeCode}), + ObjectFormat: optional.Some(name), + }) + defer f() + + portMatcher := regexp.MustCompile(`localhost:\d+`) + resp := session.MakeRequest(t, NewRequest(t, "GET", "/"+repo.FullName()), http.StatusOK) htmlDoc := NewHTMLParser(t, resp.Body) - assert.Equal(t, `touch README.md -git init --object-format=sha256 + assert.Equal(t, fmt.Sprintf(`touch README.md +%s git switch -c main git add README.md git commit -m "first commit" -git remote add origin http://localhost/user2/sha256-instruction.git -git push -u origin main`, portMatcher.ReplaceAllString(htmlDoc.Find(".empty-repo-guide code").First().Text(), "localhost")) - }) - - t.Run("sha1", func(t *testing.T) { - defer tests.PrintCurrentTest(t)() - - resp := session.MakeRequest(t, NewRequest(t, "GET", "/"+sha1Repo.FullName()), http.StatusOK) - - htmlDoc := NewHTMLParser(t, resp.Body) - assert.Equal(t, `touch README.md -git init -git switch -c main -git add README.md -git commit -m "first commit" -git remote add origin http://localhost/user2/sha1-instruction.git -git push -u origin main`, portMatcher.ReplaceAllString(htmlDoc.Find(".empty-repo-guide code").First().Text(), "localhost")) +git remote add origin http://localhost/user2/%s-instruction.git +git push -u origin main`, init, name), portMatcher.ReplaceAllString(htmlDoc.Find(".empty-repo-guide code").First().Text(), "localhost")) }) }