test(api): merge repeated cases into tables, drop skips dbtest already makes (#8295)
release / web (push) Successful in 1m34s
release / go (push) Successful in 2m0s
release / govulncheck (push) Successful in 19s
release / integration (push) Successful in 3m24s
release / android (push) Successful in 4m46s
release / Build signed APK (push) Successful in 5m12s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Publish the release image to GHCR (dispatch only) (push) Skipped
release / Build + push container image (push) Successful in 29s
release / Verify release artifacts (tag releases only) (push) Skipped
release / web (push) Successful in 1m34s
release / go (push) Successful in 2m0s
release / govulncheck (push) Successful in 19s
release / integration (push) Successful in 3m24s
release / android (push) Successful in 4m46s
release / Build signed APK (push) Successful in 5m12s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Publish the release image to GHCR (dispatch only) (push) Skipped
release / Build + push container image (push) Successful in 29s
release / Verify release artifacts (tag releases only) (push) Skipped
- The like/unlike story runs as one sequence that checks the rows after each step. - The invite-only sign-up cases are one test, which now also checks that a refused sign-up creates no account. - Demoting an admin, and stopping at the last one, is one test. - A wrong password and an unknown user are one test, which now also checks that the two refusals are identical. - The cover-path resolver tests repeated the cover handler's tests branch for branch; the handler tests stay. - The Range-from-start stream test only re-checked http.ServeContent. - The APK's nil-user 401 is covered by the mounted-route walk. - 68 copies of the MINSTREL_TEST_DATABASE_URL skip go: every one of those tests reaches dbtest.Pool, which already skips. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -10,9 +10,6 @@ import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
|
||||
"github.com/Fabled-Sword/minstrel/internal/apierror"
|
||||
"github.com/Fabled-Sword/minstrel/internal/coverart"
|
||||
"github.com/Fabled-Sword/minstrel/internal/db/dbq"
|
||||
@@ -70,72 +67,6 @@ func TestFindSidecarCover_NoneFound(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolveAlbumCoverPath_ExplicitPresent(t *testing.T) {
|
||||
_, pool := testHandlers(t)
|
||||
truncateLibrary(t, pool)
|
||||
artist := seedArtist(t, pool, "A")
|
||||
album := seedAlbum(t, pool, artist.ID, "X", 0)
|
||||
|
||||
dir := t.TempDir()
|
||||
explicit := filepath.Join(dir, "explicit.jpg")
|
||||
if err := os.WriteFile(explicit, []byte("e"), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := pool.Exec(context.Background(),
|
||||
`UPDATE albums SET cover_art_path = $1 WHERE id = $2`, explicit, album.ID); err != nil {
|
||||
t.Fatalf("UPDATE albums: %v", err)
|
||||
}
|
||||
got := resolveAlbumCoverPath(context.Background(), dbq.New(pool), fetchAlbum(t, pool, album.ID))
|
||||
if got != explicit {
|
||||
t.Errorf("got %q, want %q", got, explicit)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolveAlbumCoverPath_ExplicitMissingFallsThroughToSidecar(t *testing.T) {
|
||||
_, pool := testHandlers(t)
|
||||
truncateLibrary(t, pool)
|
||||
artist := seedArtist(t, pool, "A")
|
||||
album := seedAlbum(t, pool, artist.ID, "X", 0)
|
||||
|
||||
_, dir := seedTrackWithFile(t, pool, album.ID, artist.ID, "t", []byte("audio"), "mp3")
|
||||
sidecar := filepath.Join(dir, "cover.jpg")
|
||||
if err := os.WriteFile(sidecar, []byte("s"), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := pool.Exec(context.Background(),
|
||||
`UPDATE albums SET cover_art_path = $1 WHERE id = $2`,
|
||||
filepath.Join(dir, "does-not-exist.jpg"), album.ID); err != nil {
|
||||
t.Fatalf("UPDATE albums: %v", err)
|
||||
}
|
||||
|
||||
got := resolveAlbumCoverPath(context.Background(), dbq.New(pool), fetchAlbum(t, pool, album.ID))
|
||||
if got != sidecar {
|
||||
t.Errorf("got %q, want %q", got, sidecar)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolveAlbumCoverPath_NoArt(t *testing.T) {
|
||||
_, pool := testHandlers(t)
|
||||
truncateLibrary(t, pool)
|
||||
artist := seedArtist(t, pool, "A")
|
||||
album := seedAlbum(t, pool, artist.ID, "X", 0)
|
||||
seedTrack(t, pool, album.ID, artist.ID, "t", 1, 1000)
|
||||
got := resolveAlbumCoverPath(context.Background(), dbq.New(pool), album)
|
||||
if got != "" {
|
||||
t.Errorf("got %q, want empty string", got)
|
||||
}
|
||||
}
|
||||
|
||||
// fetchAlbum reloads the album row so tests see updates made via raw SQL.
|
||||
func fetchAlbum(t *testing.T, pool *pgxpool.Pool, id pgtype.UUID) dbq.Album {
|
||||
t.Helper()
|
||||
a, err := dbq.New(pool).GetAlbumByID(context.Background(), id)
|
||||
if err != nil {
|
||||
t.Fatalf("GetAlbumByID: %v", err)
|
||||
}
|
||||
return a
|
||||
}
|
||||
|
||||
func TestHandleGetCover_SidecarHappyPath(t *testing.T) {
|
||||
h, pool := testHandlers(t)
|
||||
truncateLibrary(t, pool)
|
||||
@@ -285,30 +216,6 @@ func TestHandleGetStream_HappyPath(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandleGetStream_RangeFromStart(t *testing.T) {
|
||||
h, pool := testHandlers(t)
|
||||
truncateLibrary(t, pool)
|
||||
artist := seedArtist(t, pool, "A")
|
||||
album := seedAlbum(t, pool, artist.ID, "X", 0)
|
||||
body := deterministicBytes(32 * 1024)
|
||||
track, _ := seedTrackWithFile(t, pool, album.ID, artist.ID, "t", body, "mp3")
|
||||
|
||||
req := httptest.NewRequest(http.MethodGet, "/api/tracks/"+uuidToString(track.ID)+"/stream", nil)
|
||||
req.Header.Set("Range", "bytes=0-99")
|
||||
w := httptest.NewRecorder()
|
||||
newLibraryRouter(h).ServeHTTP(w, req)
|
||||
|
||||
if w.Code != http.StatusPartialContent {
|
||||
t.Fatalf("status = %d, want 206", w.Code)
|
||||
}
|
||||
if cr := w.Header().Get("Content-Range"); cr != "bytes 0-99/32768" {
|
||||
t.Errorf("Content-Range = %q", cr)
|
||||
}
|
||||
if got := w.Body.Bytes(); !bytes.Equal(got, body[:100]) {
|
||||
t.Errorf("body mismatch: len=%d, want 100", len(got))
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandleGetStream_RangeFromMiddleToEnd(t *testing.T) {
|
||||
h, pool := testHandlers(t)
|
||||
truncateLibrary(t, pool)
|
||||
|
||||
Reference in New Issue
Block a user