mirror of
https://github.com/go-gitea/gitea.git
synced 2026-05-22 23:54:42 +02:00
This MR fixes an issue in the sync push mirrors endpoint. Previously, when triggering the synchronization of all push mirrors for a specific repository, the entire operation would stop if a single mirror failed for any reason. As a result, the remaining mirrors were not processed. With this fix, failures on individual push mirrors no longer abort the whole synchronization process. --------- Signed-off-by: Nicolas <bircni@icloud.com> Co-authored-by: Nicolas <bircni@icloud.com> Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: Claude (Opus 4.7) <noreply@anthropic.com>
41 lines
1.3 KiB
Go
41 lines
1.3 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package repo
|
|
|
|
import (
|
|
"net/http"
|
|
"testing"
|
|
|
|
"code.gitea.io/gitea/models/db"
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
|
"code.gitea.io/gitea/models/unittest"
|
|
"code.gitea.io/gitea/modules/setting"
|
|
"code.gitea.io/gitea/modules/test"
|
|
"code.gitea.io/gitea/services/contexttest"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
// TestPushMirrorSync verifies the endpoint attempts every push mirror instead
|
|
// of aborting on the first failure, reporting all failed remotes with a 422.
|
|
// Each remote name is not a configured git remote, so SyncPushMirror fails fast
|
|
// without any network access.
|
|
func TestPushMirrorSync(t *testing.T) {
|
|
unittest.PrepareTestEnv(t)
|
|
defer test.MockVariableValue(&setting.Mirror.Enabled, true)()
|
|
|
|
for _, remoteName := range []string{"broken_remote_1", "broken_remote_2"} {
|
|
assert.NoError(t, db.Insert(t.Context(), &repo_model.PushMirror{RepoID: 1, RemoteName: remoteName}))
|
|
}
|
|
|
|
ctx, resp := contexttest.MockAPIContext(t, "user2/repo1")
|
|
contexttest.LoadRepo(t, ctx, 1)
|
|
|
|
PushMirrorSync(ctx)
|
|
|
|
assert.Equal(t, http.StatusUnprocessableEntity, ctx.Resp.WrittenStatus())
|
|
assert.Contains(t, resp.Body.String(), "broken_remote_1")
|
|
assert.Contains(t, resp.Body.String(), "broken_remote_2")
|
|
}
|