Forgejo/services/forgejo/sanity_test.go
Earl Warren 9d3b0be39a
[UPGRADE] run sanity checks before the database is upgraded
(cherry picked from commit 69741e4e66)
(cherry picked from commit 2a3c7b09cb)
(cherry picked from commit a1554c1168)
(cherry picked from commit edae2c6d2d)
(cherry picked from commit 49737cf009)
(cherry picked from commit ec53704c34)
(cherry picked from commit 7a1c5c0f32)
(cherry picked from commit e658c20c0f)
(cherry picked from commit baf575468f)
(cherry picked from commit 40cb14eff4)
(cherry picked from commit 25ab4d0713)
(cherry picked from commit 5a29005215)
(cherry picked from commit fef1260e99)
(cherry picked from commit eadbbb1afe)
(cherry picked from commit db22d61eb4)
2023-11-27 16:16:02 +01:00

32 lines
787 B
Go

// SPDX-License-Identifier: MIT
package forgejo
import (
"os"
"path/filepath"
"testing"
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/setting"
"github.com/stretchr/testify/assert"
)
func TestForgejo_PreMigrationSanityChecks(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
ctx := db.DefaultContext
e := db.GetEngine(ctx)
assert.NoError(t, PreMigrationSanityChecks(e, ForgejoV4DatabaseVersion, configFixture(t, "")))
}
func configFixture(t *testing.T, content string) setting.ConfigProvider {
config := filepath.Join(t.TempDir(), "app.ini")
assert.NoError(t, os.WriteFile(config, []byte(content), 0o777))
cfg, err := setting.NewConfigProviderFromFile(config)
assert.NoError(t, err)
return cfg
}