release / go (push) Successful in 2m7s
release / web (push) Successful in 1m25s
release / govulncheck (push) Successful in 21s
release / integration (push) Successful in 4m30s
release / android (push) Successful in 4m39s
release / Build signed APK (push) Successful in 5m10s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Build + push container image (push) Successful in 29s
release / Verify release artifacts (tag releases only) (push) Skipped
- Module path: github.com/Fabled-Sword/minstrel, in go.mod, every import and the Dockerfile's version ldflags. - buildinfo.ProjectURL, the contact outside services see in Minstrel's User-Agent: https://github.com/Fabled-Sword/minstrel. - README's compose example pulls ghcr.io/fabled-sword/minstrel:latest. - docs/security.md sends problem reports to the GitHub issues. - The demo-library stack builds Minstrel from the checkout, since :dev is not published to GHCR. - hygiene.go's same-site example uses example.com names. The workbench CI (.gitea/, ci/, export-ignored) still builds and publishes :dev to the private registry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
107 lines
3.0 KiB
Go
107 lines
3.0 KiB
Go
package playlists_test
|
|
|
|
import (
|
|
"context"
|
|
"crypto/rand"
|
|
"fmt"
|
|
"path/filepath"
|
|
"sync/atomic"
|
|
"testing"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
"github.com/jackc/pgx/v5/pgxpool"
|
|
|
|
"github.com/Fabled-Sword/minstrel/internal/db/dbq"
|
|
"github.com/Fabled-Sword/minstrel/internal/dbtest"
|
|
)
|
|
|
|
// seedTrackCounter ensures every seedTrack call gets a unique file_path
|
|
// even when title + artist repeat. Tracks dedupe by file_path so we
|
|
// must vary it; using t.TempDir() alone isn't enough because some
|
|
// tests seed multiple tracks within one test function.
|
|
var seedTrackCounter uint64
|
|
|
|
// seedUser inserts a `test-`-prefixed user (so dbtest.ResetDB can
|
|
// clean it without touching the developer's admin row) and returns
|
|
// the persisted user record.
|
|
func seedUser(t *testing.T, pool *pgxpool.Pool, name string) dbq.User {
|
|
t.Helper()
|
|
u, err := dbq.New(pool).CreateUser(context.Background(), dbq.CreateUserParams{
|
|
Username: dbtest.TestUserPrefix + name,
|
|
PasswordHash: "x",
|
|
ApiTokenHash: name + "-token",
|
|
IsAdmin: false,
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("seed user %s: %v", name, err)
|
|
}
|
|
return u
|
|
}
|
|
|
|
// seedTrack creates an artist + album + track triple suitable for
|
|
// playlist track-list mutation tests. Each call produces a fresh
|
|
// track row with a unique file_path; artist and album are not
|
|
// deduplicated across calls (mbid-less upsert), but that's fine for
|
|
// these tests — playlist snapshots just capture the strings.
|
|
func seedTrack(t *testing.T, pool *pgxpool.Pool, title, artist string) dbq.Track {
|
|
t.Helper()
|
|
q := dbq.New(pool)
|
|
a, err := q.UpsertArtist(context.Background(), dbq.UpsertArtistParams{
|
|
Name: artist, SortName: artist,
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("seed artist: %v", err)
|
|
}
|
|
al, err := q.UpsertAlbum(context.Background(), dbq.UpsertAlbumParams{
|
|
Title: artist + " - Album", SortTitle: artist + " - Album",
|
|
ArtistID: a.ID,
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("seed album: %v", err)
|
|
}
|
|
n := atomic.AddUint64(&seedTrackCounter, 1)
|
|
track, err := q.UpsertTrack(context.Background(), dbq.UpsertTrackParams{
|
|
Title: title, AlbumID: al.ID, ArtistID: a.ID,
|
|
DurationMs: 1000,
|
|
FilePath: filepath.Join(t.TempDir(), fmt.Sprintf("%s-%d.mp3", title, n)),
|
|
FileSize: 100, FileFormat: "mp3",
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("seed track: %v", err)
|
|
}
|
|
return track
|
|
}
|
|
|
|
// randomUUID returns a fresh valid pgtype.UUID. Used in tests that
|
|
// need an id guaranteed-not-to-exist in the database.
|
|
func randomUUID() pgtype.UUID {
|
|
var u pgtype.UUID
|
|
if _, err := rand.Read(u.Bytes[:]); err != nil {
|
|
panic(err)
|
|
}
|
|
u.Valid = true
|
|
return u
|
|
}
|
|
|
|
// uuidString renders a pgtype.UUID as the canonical 8-4-4-4-12 form
|
|
// without depending on a third-party UUID package — used in tests
|
|
// that build a filename from a playlist id.
|
|
func uuidString(u pgtype.UUID) string {
|
|
if !u.Valid {
|
|
return ""
|
|
}
|
|
const hex = "0123456789abcdef"
|
|
out := make([]byte, 36)
|
|
j := 0
|
|
for i, x := range u.Bytes {
|
|
if i == 4 || i == 6 || i == 8 || i == 10 {
|
|
out[j] = '-'
|
|
j++
|
|
}
|
|
out[j] = hex[x>>4]
|
|
out[j+1] = hex[x&0x0f]
|
|
j += 2
|
|
}
|
|
return string(out)
|
|
}
|