1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2025-08-02 16:35:19 +02:00

chore: do not require empty fixtures to clean tables (#8353)

- A mistake that is often made is to not put a empty fixture for tables that gets populated in a test and should be cleaned up between runs. The CI does not detect such issues as these never arise on the first run of the test suite and are only noticed when developers run a test for a second time, unless you are aware of this behavior (which very few do as this is not documented and pure folk knowledge) can end up in chasing a bug that does not exist for hours. forgejo/forgejo#7041, forgejo/forgejo#7419, meissa/forgejo#21, forgejo/forgejo#5771
- Because we now own the fixture loader (forgejo/forgejo#7715), its rather simple to ensure that all tables that did not receive fixtures should be cleaned between runs and removes the need to place empty fixture files.

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8353
Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
Reviewed-by: Otto <otto@codeberg.org>
Co-authored-by: Gusted <postmaster@gusted.xyz>
Co-committed-by: Gusted <postmaster@gusted.xyz>
This commit is contained in:
Gusted 2025-06-30 23:04:16 +02:00 committed by Gusted
parent 6e58d285c7
commit 0ecb25fdcb
23 changed files with 96 additions and 21 deletions

View file

@ -0,0 +1,40 @@
// Copyright 2025 The Forgejo Authors. All rights reserved.
// SPDX-License-Identifier: GPL-3.0-or-later
package db
import (
"slices"
"testing"
"forgejo.org/modules/test"
"github.com/stretchr/testify/assert"
)
func TestGetTableNames(t *testing.T) {
t.Run("Simple", func(t *testing.T) {
defer test.MockVariableValue(&tables, []any{new(GPGKey)})()
assert.Equal(t, []string{"gpg_key"}, GetTableNames().Values())
})
t.Run("Multiple tables", func(t *testing.T) {
defer test.MockVariableValue(&tables, []any{new(GPGKey), new(User), new(BlockedUser)})()
tableNames := GetTableNames().Values()
slices.Sort(tableNames)
assert.Equal(t, []string{"forgejo_blocked_user", "gpg_key", "user"}, tableNames)
})
}
type GPGKey struct{}
type User struct{}
type BlockedUser struct{}
func (*BlockedUser) TableName() string {
return "forgejo_blocked_user"
}