chore: QoL improvements to tests (#7917)

- Use mock helper functions, instead of home-brew solutions.
- Disable cron jobs that are not important to be run during integration tests and might even interfere.
- Avoid sleeping unnecessary, if there's some requirement then sleep or retry until that requirement is met.
- Avoid trying to deliver webhooks that will always result in a failure.

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7917
Reviewed-by: Michael Kriese <michael.kriese@gmx.de>
Co-authored-by: Gusted <postmaster@gusted.xyz>
Co-committed-by: Gusted <postmaster@gusted.xyz>
This commit is contained in:
Gusted 2025-05-21 15:45:56 +02:00 committed by Gusted
commit fa2a135f68
44 changed files with 155 additions and 264 deletions

View file

@ -23,7 +23,7 @@ func (s *testDiscoveredInfo) OpLocalID() string {
}
func TestTimedDiscoveryCache(t *testing.T) {
dc := newTimedDiscoveryCache(1 * time.Second)
dc := newTimedDiscoveryCache(100 * time.Millisecond)
// Put some initial values
dc.Put("foo", &testDiscoveredInfo{}) // openid.opEndpoint: "a", openid.opLocalID: "b", openid.claimedID: "c"})
@ -41,7 +41,7 @@ func TestTimedDiscoveryCache(t *testing.T) {
}
// Sleep one second and try retrieve again
time.Sleep(1 * time.Second)
time.Sleep(100 * time.Millisecond)
if di := dc.Get("foo"); di != nil {
t.Errorf("Expected a nil, got a result")

View file

@ -7,19 +7,19 @@ import (
"testing"
"forgejo.org/modules/setting"
"forgejo.org/modules/test"
"github.com/stretchr/testify/assert"
)
func TestInit(t *testing.T) {
setting.Domain = "domain"
setting.AppName = "AppName"
setting.AppURL = "https://domain/"
rpOrigin := []string{"https://domain"}
defer test.MockVariableValue(&setting.Domain, "domain")()
defer test.MockVariableValue(&setting.AppName, "AppName")()
defer test.MockVariableValue(&setting.AppURL, "https://domain/")()
Init()
assert.Equal(t, setting.Domain, WebAuthn.Config.RPID)
assert.Equal(t, setting.AppName, WebAuthn.Config.RPDisplayName)
assert.Equal(t, rpOrigin, WebAuthn.Config.RPOrigins)
assert.Equal(t, []string{"https://domain"}, WebAuthn.Config.RPOrigins)
}