From 916ec9acab10a68b7a6a1b0a647f87cac9331a91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Dachary?= Date: Sat, 1 Jul 2023 01:20:44 +0200 Subject: [PATCH] [TESTS] MockVariable temporarily replaces a global value defer test.MockVariable(&variable, 1234)() (cherry picked from commit 9c78752444c2411f20e72b96b7b4fdf5359099d5) (cherry picked from commit 8ab559df0d57a17a0ea73bd3676f40a523a15ab6) (cherry picked from commit 2e7fe1ec9566e4840992e4049d8349873b7334ee) (cherry picked from commit f9618b8896a73c9316634be76b115bf2c73e0c00) Conflicts: modules/test/utils.go https://codeberg.org/forgejo/forgejo/issues/1219 --- modules/test/utils.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/modules/test/utils.go b/modules/test/utils.go index 7809882f5e..9a64a0476d 100644 --- a/modules/test/utils.go +++ b/modules/test/utils.go @@ -22,3 +22,11 @@ func MockVariableValue[T any](p *T, v T) (reset func()) { *p = v return func() { *p = old } } + +func MockVariable[T any](variable *T, mock T) func() { + original := *variable + *variable = mock + return func() { + *variable = original + } +}