mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-06-20 16:10:50 +00:00
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:
parent
112ba66637
commit
fa2a135f68
44 changed files with 155 additions and 264 deletions
|
@ -15,6 +15,7 @@ import (
|
|||
"forgejo.org/models/unittest"
|
||||
user_model "forgejo.org/models/user"
|
||||
"forgejo.org/modules/setting"
|
||||
"forgejo.org/modules/test"
|
||||
"forgejo.org/modules/web"
|
||||
"forgejo.org/services/context"
|
||||
"forgejo.org/services/contexttest"
|
||||
|
@ -25,23 +26,8 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func createSSHAuthorizedKeysTmpPath(t *testing.T) func() {
|
||||
tmpDir := t.TempDir()
|
||||
|
||||
oldPath := setting.SSH.RootPath
|
||||
setting.SSH.RootPath = tmpDir
|
||||
|
||||
return func() {
|
||||
setting.SSH.RootPath = oldPath
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddReadOnlyDeployKey(t *testing.T) {
|
||||
if deferable := createSSHAuthorizedKeysTmpPath(t); deferable != nil {
|
||||
defer deferable()
|
||||
} else {
|
||||
return
|
||||
}
|
||||
defer test.MockVariableValue(&setting.SSH.RootPath, t.TempDir())()
|
||||
unittest.PrepareTestEnv(t)
|
||||
|
||||
ctx, _ := contexttest.MockContext(t, "user2/repo1/settings/keys")
|
||||
|
@ -65,11 +51,7 @@ func TestAddReadOnlyDeployKey(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestAddReadWriteOnlyDeployKey(t *testing.T) {
|
||||
if deferable := createSSHAuthorizedKeysTmpPath(t); deferable != nil {
|
||||
defer deferable()
|
||||
} else {
|
||||
return
|
||||
}
|
||||
defer test.MockVariableValue(&setting.SSH.RootPath, t.TempDir())()
|
||||
|
||||
unittest.PrepareTestEnv(t)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue