From c28ef4f7b4fc07776ebf5245fb7fecdc451b0ac0 Mon Sep 17 00:00:00 2001 From: kolaente Date: Mon, 20 Jul 2026 13:26:11 +0200 Subject: [PATCH] test(migration): drop the manually created index and dedupe username-index helpers address pr-swarm findings: the non-model index leaked into later tests via the singleton test engine; the singular helper duplicated the list helper --- pkg/migration/20260720120000_test.go | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/pkg/migration/20260720120000_test.go b/pkg/migration/20260720120000_test.go index 0dd83bbd3..62a5f6e0f 100644 --- a/pkg/migration/20260720120000_test.go +++ b/pkg/migration/20260720120000_test.go @@ -37,21 +37,11 @@ func (usersPartial20260720120000) TableName() string { func usersIndexOnUsername20260720120000(t *testing.T, x *xorm.Engine) *schemas.Index { t.Helper() - tables, err := x.DBMetas() - require.NoError(t, err) - for _, table := range tables { - if table.Name != "users" { - continue - } - for _, index := range table.Indexes { - if len(index.Cols) == 1 && index.Cols[0] == "username" { - return index - } - } + indexes := usersIndexesOnUsername20260720120000(t, x) + if len(indexes) == 0 { return nil } - t.Fatal("users table not found") - return nil + return indexes[0] } func TestRecreateMissingIndexes20260720120000(t *testing.T) { @@ -117,6 +107,11 @@ func TestRecreateMissingIndexesKeepsDifferentlyNamedIndex20260720120000(t *testi _, err = x.Exec("CREATE UNIQUE INDEX some_nonmodel_name ON users (username)") require.NoError(t, err) + t.Cleanup(func() { + // x is the process-global test engine; leaving this index around leaks into later tests. + _, err := x.Exec("DROP INDEX some_nonmodel_name") + require.NoError(t, err) + }) require.NoError(t, recreateMissingIndexes20260720120000(x))