Migration round trip (family idea "Migration CI lane"): - TestMigrationsRoundTrip, in the integration lane, migrates a scratch database to the baseline, then all the way up, then every migration after the baseline down, then up again. - The schema after the down pass must match a database migrated to the baseline alone: columns, indexes, constraints, sequences, enums, functions and triggers. So a down file that leaves something behind fails, as well as one that errors. - The baseline's own down file refuses to run by design, so the round trip stops there. - The test uses golang-migrate as a library, with no migrator binary. - The scratch database is dropped afterwards, and the shared test database is never migrated down. dbtest (family idea "dbtest Pool and Fixtures"): - dbtest.URL skips without a database. It fails instead when MINSTREL_TEST_DATABASE_REQUIRED is set, and the integration lane sets it. - dbtest.On(t, db) gives One/Exec/Count fixtures. The local copies are repointed to them: exec in api, mustExec/mustID in backup, countQueueRows in scrobble, and countTrackSim/countArtistSim in similarity. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
@@ -9,7 +8,7 @@ import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
"github.com/Fabled-Sword/minstrel/internal/dbtest"
|
||||
)
|
||||
|
||||
// getArt fetches path and returns the image body, or "" with the status
|
||||
@@ -52,13 +51,6 @@ func detailCoverURL(t *testing.T, h *handlers, id string) string {
|
||||
return got.CoverURL
|
||||
}
|
||||
|
||||
func exec(t *testing.T, pool *pgxpool.Pool, sql string, args ...any) {
|
||||
t.Helper()
|
||||
if _, err := pool.Exec(context.Background(), sql, args...); err != nil {
|
||||
t.Fatalf("%s: %v", sql, err)
|
||||
}
|
||||
}
|
||||
|
||||
// An artist's image is the picture fetched for them, or else their newest
|
||||
// album cover; artist listings point at it when there is a picture, and the
|
||||
// artist page whenever the artist has albums.
|
||||
@@ -75,7 +67,7 @@ func TestArtistImage_PictureOrNewestAlbumCover(t *testing.T) {
|
||||
}
|
||||
orchard := seedArtist(t, pool, "Tin Orchard")
|
||||
album := seedAlbum(t, pool, orchard.ID, "Paper Boats", 2012)
|
||||
exec(t, pool, `UPDATE albums SET cover_art_path = $2 WHERE id = $1`, album.ID, write("boats.jpg", "boats"))
|
||||
dbtest.On(t, pool).Exec(`UPDATE albums SET cover_art_path = $2 WHERE id = $1`, album.ID, write("boats.jpg", "boats"))
|
||||
quiet := seedArtist(t, pool, "Quiet Field")
|
||||
orchardImage := "/api/artists/" + uuidToString(orchard.ID) + "/image"
|
||||
albumCover := "/api/albums/" + uuidToString(album.ID) + "/cover"
|
||||
@@ -87,7 +79,7 @@ func TestArtistImage_PictureOrNewestAlbumCover(t *testing.T) {
|
||||
t.Errorf("no picture: listing cover_url = %v, want the album cover for Tin Orchard and none for Quiet Field", got)
|
||||
}
|
||||
|
||||
exec(t, pool, `UPDATE artists SET artist_thumb_path = $2 WHERE id = $1`, orchard.ID, write("thumb.jpg", "thumb"))
|
||||
dbtest.On(t, pool).Exec(`UPDATE artists SET artist_thumb_path = $2 WHERE id = $1`, orchard.ID, write("thumb.jpg", "thumb"))
|
||||
if got, code := getArt(t, h, orchardImage); got != "thumb" {
|
||||
t.Errorf("with a picture: got %q (status %d), want the picture", got, code)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user