Files
bvandeusen a8fd33d4ed chore(lint): clear pre-existing CI lint debt
Nine golangci-lint failures accumulated across M7 #352, #372, and
6d1709c that were never surfaced because test-go never ran green long
enough to reach the lint step. The first push to land cleanly through
vet (the M7 #363 slice) ran lint and exposed them.

- errcheck: discard the error on defer Close() in collage.go,
  collage_test.go, and server_test.go.
- gofmt -s: re-run on config.go and playlists_test.go.
- goimports: move the stray "time" import from the local-module group
  to stdlib in server_test.go.
- revive unused-parameter: rename ctx to _ on stubScanner.Scan and
  fakeLidarrUnmonitorer.UnmonitorTrack (test stubs); on
  tracks.Service's adminID, add //nolint:revive directive rather than
  renaming because the HTTP handler passes admin.ID (a real authed-user
  UUID) and the existing comment already flags it as reserved for the
  audit-log follow-up.
2026-05-03 18:59:58 -04:00

76 lines
1.9 KiB
Go

package playlists_test
import (
"context"
"image"
_ "image/jpeg"
"os"
"path/filepath"
"testing"
"github.com/jackc/pgx/v5/pgtype"
"git.fabledsword.com/bvandeusen/minstrel/internal/playlists"
)
func TestGenerateCollage_EmptyPlaylist(t *testing.T) {
pool := newPool(t)
user := seedUser(t, pool, "alice")
dir := t.TempDir()
svc := playlists.NewService(pool, nil, dir)
pl, err := svc.Create(context.Background(), user.ID, "Empty", "", false)
if err != nil {
t.Fatalf("Create: %v", err)
}
relPath, err := playlists.GenerateCollage(context.Background(), pool, pl.ID, dir)
if err != nil {
t.Fatalf("GenerateCollage: %v", err)
}
if relPath != "" {
t.Errorf("relPath = %q, want \"\" for empty playlist", relPath)
}
}
func TestGenerateCollage_OneTrack(t *testing.T) {
pool := newPool(t)
user := seedUser(t, pool, "alice")
tk := seedTrack(t, pool, "Roygbiv", "BoC")
dir := t.TempDir()
svc := playlists.NewService(pool, nil, dir)
pl, err := svc.Create(context.Background(), user.ID, "One", "", false)
if err != nil {
t.Fatalf("Create: %v", err)
}
if err := svc.AppendTracks(context.Background(), user.ID, pl.ID, []pgtype.UUID{tk.ID}); err != nil {
t.Fatalf("AppendTracks: %v", err)
}
got, err := svc.Get(context.Background(), user.ID, pl.ID)
if err != nil {
t.Fatalf("Get: %v", err)
}
if got.CoverPath == nil || *got.CoverPath == "" {
t.Fatalf("CoverPath empty after append")
}
full := filepath.Join(dir, *got.CoverPath)
f, err := os.Open(full)
if err != nil {
t.Fatalf("open collage: %v", err)
}
defer func() { _ = f.Close() }()
img, format, err := image.Decode(f)
if err != nil {
t.Fatalf("decode collage: %v", err)
}
if format != "jpeg" {
t.Errorf("format = %q, want jpeg", format)
}
if img.Bounds().Dx() != 600 || img.Bounds().Dy() != 600 {
t.Errorf("dimensions = %dx%d, want 600x600", img.Bounds().Dx(), img.Bounds().Dy())
}
}