From d900842fd76819859bded307a61191006d2b1a80 Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Wed, 29 May 2024 19:52:26 +0200 Subject: [PATCH] test(mock): DeletePushMirrors & AddPushMirrorRemote make them into variables that can be mocked (cherry picked from commit 5747951cc7c3bce05b593447168cd6337965054b) --- models/repo/pushmirror.go | 4 +++- services/mirror/mirror_push.go | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/models/repo/pushmirror.go b/models/repo/pushmirror.go index e08333511c..3cf54facae 100644 --- a/models/repo/pushmirror.go +++ b/models/repo/pushmirror.go @@ -94,7 +94,9 @@ func UpdatePushMirrorInterval(ctx context.Context, m *PushMirror) error { return err } -func DeletePushMirrors(ctx context.Context, opts PushMirrorOptions) error { +var DeletePushMirrors = deletePushMirrors + +func deletePushMirrors(ctx context.Context, opts PushMirrorOptions) error { if opts.RepoID > 0 { _, err := db.Delete[PushMirror](ctx, opts) return err diff --git a/services/mirror/mirror_push.go b/services/mirror/mirror_push.go index 21ba0afeff..8303c9fb0c 100644 --- a/services/mirror/mirror_push.go +++ b/services/mirror/mirror_push.go @@ -28,7 +28,9 @@ import ( var stripExitStatus = regexp.MustCompile(`exit status \d+ - `) // AddPushMirrorRemote registers the push mirror remote. -func AddPushMirrorRemote(ctx context.Context, m *repo_model.PushMirror, addr string) error { +var AddPushMirrorRemote = addPushMirrorRemote + +func addPushMirrorRemote(ctx context.Context, m *repo_model.PushMirror, addr string) error { addRemoteAndConfig := func(addr, path string) error { cmd := git.NewCommand(ctx, "remote", "add", "--mirror=push").AddDynamicArguments(m.RemoteName, addr) if strings.Contains(addr, "://") && strings.Contains(addr, "@") {