1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-12-30 14:09:42 -05:00
forgejo/modules/test
Earl Warren 35d5ef0649 test(util): MockProtect when mocking multiple times
It is fine to use MockVariableValue to change a setting such as:

defer test.MockVariableValue(&setting.Mirror.Enabled, true)()

But when testing for errors and mocking a function, multiple variants
of the functions will be used, not just one. MockProtect a function
will make sure that when the test fails it always restores a sane
version of the function. For instance:

defer test.MockProtect(&mirror_service.AddPushMirrorRemote)()

mirror_service.AddPushMirrorRemote = mockOne
do some tests that may fail

mirror_service.AddPushMirrorRemote = mockTwo
do more tests that may fail

(cherry picked from commit 884b3c0f4b)
2024-06-02 14:32:00 +00:00
..
logchecker.go [TESTS] add log.Level to test.NewLogChecker 2024-02-05 16:54:44 +01:00
logchecker_test.go [TESTS] add log.Level to test.NewLogChecker 2024-02-05 16:54:44 +01:00
utils.go test(util): MockProtect when mocking multiple times 2024-06-02 14:32:00 +00:00
utils_test.go test(util): MockProtect when mocking multiple times 2024-06-02 14:32:00 +00:00