Rewrite tests to run without a database

- Unit tests use an in-memory fake database (internal/testutil/fakedb),
  temp folders and httptest; `go test ./...` needs no Docker or env vars
- Integration tests (build tag "integration") start PostgreSQL with
  testcontainers: migrations step by step, SQL dumps (skipped if
  missing) and a full sync against a real database
- Removed tests that only checked copies of the logic or had empty
  bodies, the broken root integration_test.go, compose.test.yaml and
  .env.test with hardcoded paths
- testMusic MP3s replaced with tiny placeholders (sync never decodes
  audio), 194 MB -> 168 KB
This commit is contained in:
Sansan committed 2026-10-06 15:20:31 +02:00
1 parent 090e794460
commit 7b144ae419
42 files changed
+2334 -40

No files matched your search

+39
View File
@@ -0,0 +1,39 @@
//go:build integration
package db_test
import (
"os"
"path/filepath"
"testing"
"music-server/internal/testutil/pgtest"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// TestSQLDumps migrates real database dumps (music_*_dump.sql in the repository root, not committed).
func TestSQLDumps(t *testing.T) {
for _, dump := range []string{"music_ref_dump.sql", "music_test_dump.sql", "music_prod_dump.sql"} {
t.Run(dump, func(t *testing.T) {
path := filepath.Join("..", "..", dump)
if _, err := os.Stat(path); err != nil {
t.Skipf("%s not found", dump)
}
pgtest.CreateRole(t, "sansan")
dbname := pgtest.NewDatabase(t)
pgtest.LoadSQLFile(t, dbname, path)
database := openDatabase(t, dbname)
soundtracksBefore := count(t, database, "SELECT COUNT(*) FROM game")
songsBefore := count(t, database, "SELECT COUNT(*) FROM song")
require.NoError(t, database.RunMigrations())
assert.Equal(t, soundtracksBefore, count(t, database, "SELECT COUNT(*) FROM soundtrack"))
assert.Equal(t, songsBefore, count(t, database, "SELECT COUNT(*) FROM song"))
assert.Equal(t, 0, count(t, database, "SELECT COUNT(*) FROM song WHERE uuid IS NULL"))
})
}
}