mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-06-27 16:35:57 +00:00
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 <wetneb@noreply.codeberg.org> Reviewed-by: oliverpool <oliverpool@noreply.codeberg.org> Co-authored-by: Earl Warren <contact@earl-warren.org> Co-committed-by: Earl Warren <contact@earl-warren.org>
This commit is contained in:
parent
34987a2be7
commit
e934d0a3f3
1 changed files with 22 additions and 39 deletions
|
@ -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"))
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue