mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-26 06:16:56 +09:00
test: fix unit tests failing on repeated runs (#39915)
`go test -count=2` failed in 12 packages because tests leaked state into later runs. - Reset SQLite sequences after each fixture load, like PostgreSQL already does - Prepare the database in tests that relied on earlier tests doing it - Restore mutated globals with `test.MockVariableValue`
This commit is contained in:
1 parent
ef55965d98
commit
98c613d943
20 files changed
+124
-66
No files matched your search
@@ -6,6 +6,8 @@ package setting
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"gitea.dev/modules/test"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@@ -103,6 +105,9 @@ STORAGE_TYPE = minio
|
||||
}
|
||||
|
||||
func Test_LFSClientServerConfigs(t *testing.T) {
|
||||
defer test.MockVariableValue(&LFS)()
|
||||
defer test.MockVariableValue(&LFSClient)()
|
||||
|
||||
iniStr := `
|
||||
[server]
|
||||
LFS_MAX_BATCH_SIZE = 100
|
||||
|
||||
@@ -6,10 +6,17 @@ package setting
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"gitea.dev/modules/test"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestLoadMarkup(t *testing.T) {
|
||||
defer test.MockVariableValue(&Markdown)()
|
||||
defer test.MockVariableValue(&ExternalMarkupRenderers)()
|
||||
defer test.MockVariableValue(&ExternalSanitizerRules)()
|
||||
defer test.MockVariableValue(&MermaidMaxSourceCharacters)()
|
||||
|
||||
cfg, _ := NewConfigProviderFromData(``)
|
||||
loadMarkupFrom(cfg)
|
||||
assert.Equal(t, MarkdownMathCodeBlockOptions{ParseInlineDollar: true, ParseBlockDollar: true}, Markdown.MathCodeBlockOptions)
|
||||
|
||||
@@ -60,6 +60,8 @@ func TestGetGeneralSigningSecretSave(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestOauth2DefaultApplications(t *testing.T) {
|
||||
defer test.MockVariableValue(&OAuth2)()
|
||||
|
||||
cfg, _ := NewConfigProviderFromData(``)
|
||||
loadOAuth2From(cfg)
|
||||
assert.Equal(t, []string{"git-credential-oauth", "git-credential-manager", "tea", "gitea-app", "gitea-vscode"}, OAuth2.DefaultApplications)
|
||||
|
||||
@@ -6,10 +6,14 @@ package setting
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"gitea.dev/modules/test"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestLoadSecurityFrom(t *testing.T) {
|
||||
defer test.MockVariableValue(&Security)()
|
||||
|
||||
assert.Equal(t, "SAMEORIGIN", Security.XFrameOptions)
|
||||
assert.Equal(t, "nosniff", Security.XContentTypeOptions)
|
||||
assert.Equal(t, "lax", Security.EgressMode)
|
||||
|
||||
Reference in new issue
Block a user