1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-12-01 09:51:39 -05:00

Merge pull request 'tests: A workaround for the MySQL collation tests' (#2272) from algernon/forgejo:b/mysql-collate-test-workaround into forgejo-dependency

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/2272
Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
This commit is contained in:
Earl Warren 2024-01-31 22:45:40 +00:00
commit 40e927c493

View file

@ -5,10 +5,12 @@ package integration
import ( import (
"testing" "testing"
"time"
"code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/test" "code.gitea.io/gitea/modules/test"
"code.gitea.io/gitea/tests"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"xorm.io/xorm" "xorm.io/xorm"
@ -48,6 +50,8 @@ func TestDatabaseCollation(t *testing.T) {
} }
t.Run("Default startup makes database collation case-sensitive", func(t *testing.T) { t.Run("Default startup makes database collation case-sensitive", func(t *testing.T) {
defer tests.PrintCurrentTest(t)()
r, err := db.CheckCollations(x) r, err := db.CheckCollations(x)
assert.NoError(t, err) assert.NoError(t, err)
assert.True(t, r.IsCollationCaseSensitive(r.DatabaseCollation)) assert.True(t, r.IsCollationCaseSensitive(r.DatabaseCollation))
@ -78,8 +82,12 @@ func TestDatabaseCollation(t *testing.T) {
} }
t.Run("Convert tables to utf8mb4_bin", func(t *testing.T) { t.Run("Convert tables to utf8mb4_bin", func(t *testing.T) {
defer tests.PrintCurrentTest(t)()
defer test.MockVariableValue(&setting.Database.CharsetCollation, "utf8mb4_bin")() defer test.MockVariableValue(&setting.Database.CharsetCollation, "utf8mb4_bin")()
assert.NoError(t, db.ConvertDatabaseTable()) assert.NoError(t, db.ConvertDatabaseTable())
time.Sleep(5 * time.Second)
r, err := db.CheckCollations(x) r, err := db.CheckCollations(x)
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, "utf8mb4_bin", r.DatabaseCollation) assert.Equal(t, "utf8mb4_bin", r.DatabaseCollation)
@ -95,8 +103,12 @@ func TestDatabaseCollation(t *testing.T) {
}) })
t.Run("Convert tables to utf8mb4_general_ci", func(t *testing.T) { t.Run("Convert tables to utf8mb4_general_ci", func(t *testing.T) {
defer tests.PrintCurrentTest(t)()
defer test.MockVariableValue(&setting.Database.CharsetCollation, "utf8mb4_general_ci")() defer test.MockVariableValue(&setting.Database.CharsetCollation, "utf8mb4_general_ci")()
assert.NoError(t, db.ConvertDatabaseTable()) assert.NoError(t, db.ConvertDatabaseTable())
time.Sleep(5 * time.Second)
r, err := db.CheckCollations(x) r, err := db.CheckCollations(x)
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, "utf8mb4_general_ci", r.DatabaseCollation) assert.Equal(t, "utf8mb4_general_ci", r.DatabaseCollation)
@ -112,8 +124,12 @@ func TestDatabaseCollation(t *testing.T) {
}) })
t.Run("Convert tables to default case-sensitive collation", func(t *testing.T) { t.Run("Convert tables to default case-sensitive collation", func(t *testing.T) {
defer tests.PrintCurrentTest(t)()
defer test.MockVariableValue(&setting.Database.CharsetCollation, "")() defer test.MockVariableValue(&setting.Database.CharsetCollation, "")()
assert.NoError(t, db.ConvertDatabaseTable()) assert.NoError(t, db.ConvertDatabaseTable())
time.Sleep(5 * time.Second)
r, err := db.CheckCollations(x) r, err := db.CheckCollations(x)
assert.NoError(t, err) assert.NoError(t, err)
assert.True(t, r.IsCollationCaseSensitive(r.DatabaseCollation)) assert.True(t, r.IsCollationCaseSensitive(r.DatabaseCollation))