Fixed some small bugs after merge

This commit is contained in:
2026-06-14 11:30:58 +02:00
parent 0894d65ec5
commit 4e5bdc4ee2
21 changed files with 1460 additions and 186 deletions
+25 -9
View File
@@ -54,8 +54,19 @@ func TestSetupDB(t *testing.T) {
t.Fatalf("Failed to initialize test database: %v", err)
}
// Clean up any existing schema to ensure clean state
ctx := context.Background()
_, err = TestDatabase.Pool.Exec(ctx, "DROP SCHEMA IF EXISTS public CASCADE; CREATE SCHEMA public;")
if err != nil {
t.Logf("Warning: Could not clean schema: %v", err)
// Continue anyway, migrations might still work
}
// Run migrations
if err := TestDatabase.RunMigrations(); err != nil {
// Clean up on failure to prevent nil pointer issues in other tests
TestDatabase.Close()
TestDatabase = nil
t.Fatalf("Failed to run migrations: %v", err)
}
})
@@ -97,10 +108,11 @@ func createTestDatabase(host, port, dbname, user, password string) {
// "closed pool" errors when tests run sequentially
func TestTearDownDB(t *testing.T) {
// CloseDb() // Disabled to prevent pool closure between sequential tests
if TestDatabase != nil {
TestDatabase.Close()
TestDatabase = nil
}
// Note: We also don't nil TestDatabase to allow reuse across tests
// if TestDatabase != nil {
// TestDatabase.Close()
// TestDatabase = nil
// }
}
// TestClearDatabase clears all data from the test database
@@ -112,10 +124,13 @@ func TestClearDatabase(t *testing.T) {
// Clear all tables in reverse order to respect foreign keys
// Note: This assumes the tables exist and have the expected structure
// After migration 000005, game table was renamed to soundtrack
tables := []string{
"song_list",
"song",
"game",
"soundtrack",
"vgmq",
"sessions",
}
ctx := context.Background()
@@ -126,9 +141,10 @@ func TestClearDatabase(t *testing.T) {
}
}
// Reset sequences
_, err := TestDatabase.Pool.Exec(ctx, "SELECT setval('game_id_seq', 1, false)")
if err != nil {
t.Logf("Failed to reset game_id_seq: %v", err)
// Reset sequences (renamed from game_id_seq to soundtrack_id_seq in migration 000005)
var seqErr error
_, seqErr = TestDatabase.Pool.Exec(ctx, "SELECT setval('soundtrack_id_seq', 1, false)")
if seqErr != nil {
t.Logf("Failed to reset soundtrack_id_seq: %v", seqErr)
}
}