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>
117 lines
3.3 KiB
Go
117 lines
3.3 KiB
Go
package playsessions
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
"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"
|
|
)
|
|
|
|
func seedTestUser(t *testing.T, pool *pgxpool.Pool) pgtype.UUID {
|
|
t.Helper()
|
|
u, err := dbq.New(pool).CreateUser(context.Background(), dbq.CreateUserParams{
|
|
Username: dbtest.TestUserPrefix + "tester",
|
|
PasswordHash: "x",
|
|
ApiTokenHash: "x",
|
|
IsAdmin: false,
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("CreateUser: %v", err)
|
|
}
|
|
return u.ID
|
|
}
|
|
|
|
func TestFindOrCreate_NoPriorSessionCreatesOne(t *testing.T) {
|
|
pool := dbtest.Pool(t)
|
|
user := seedTestUser(t, pool)
|
|
q := dbq.New(pool)
|
|
|
|
now := time.Date(2026, 4, 25, 12, 0, 0, 0, time.UTC)
|
|
id, err := FindOrCreate(context.Background(), q, user, now, "client-a", 30*time.Minute)
|
|
if err != nil {
|
|
t.Fatalf("FindOrCreate: %v", err)
|
|
}
|
|
if !id.Valid {
|
|
t.Fatalf("session id not valid")
|
|
}
|
|
row, err := q.GetMostRecentPlaySessionForUser(context.Background(), user)
|
|
if err != nil {
|
|
t.Fatalf("get session: %v", err)
|
|
}
|
|
if row.ID != id {
|
|
t.Errorf("returned id %v, db has %v", id, row.ID)
|
|
}
|
|
if !row.StartedAt.Time.Equal(now) {
|
|
t.Errorf("started_at = %v, want %v", row.StartedAt.Time, now)
|
|
}
|
|
}
|
|
|
|
func TestFindOrCreate_WithinWindowExtendsExisting(t *testing.T) {
|
|
pool := dbtest.Pool(t)
|
|
user := seedTestUser(t, pool)
|
|
q := dbq.New(pool)
|
|
|
|
now := time.Date(2026, 4, 25, 12, 0, 0, 0, time.UTC)
|
|
first, err := FindOrCreate(context.Background(), q, user, now, "client-a", 30*time.Minute)
|
|
if err != nil {
|
|
t.Fatalf("first: %v", err)
|
|
}
|
|
second, err := FindOrCreate(context.Background(), q, user, now.Add(15*time.Minute), "client-a", 30*time.Minute)
|
|
if err != nil {
|
|
t.Fatalf("second: %v", err)
|
|
}
|
|
if first != second {
|
|
t.Errorf("session id changed: %v -> %v", first, second)
|
|
}
|
|
row, err := q.GetMostRecentPlaySessionForUser(context.Background(), user)
|
|
if err != nil {
|
|
t.Fatalf("get session: %v", err)
|
|
}
|
|
if !row.LastEventAt.Time.Equal(now.Add(15 * time.Minute)) {
|
|
t.Errorf("last_event_at = %v", row.LastEventAt.Time)
|
|
}
|
|
if row.TrackCount != 2 {
|
|
t.Errorf("track_count = %d, want 2", row.TrackCount)
|
|
}
|
|
}
|
|
|
|
func TestFindOrCreate_BeyondWindowStartsNew(t *testing.T) {
|
|
pool := dbtest.Pool(t)
|
|
user := seedTestUser(t, pool)
|
|
q := dbq.New(pool)
|
|
|
|
now := time.Date(2026, 4, 25, 12, 0, 0, 0, time.UTC)
|
|
first, err := FindOrCreate(context.Background(), q, user, now, "client-a", 30*time.Minute)
|
|
if err != nil {
|
|
t.Fatalf("first: %v", err)
|
|
}
|
|
second, err := FindOrCreate(context.Background(), q, user, now.Add(31*time.Minute), "client-a", 30*time.Minute)
|
|
if err != nil {
|
|
t.Fatalf("second: %v", err)
|
|
}
|
|
if first == second {
|
|
t.Errorf("expected new session, got same id %v", first)
|
|
}
|
|
}
|
|
|
|
func TestFindOrCreate_AtExactBoundaryExtendsExisting(t *testing.T) {
|
|
pool := dbtest.Pool(t)
|
|
user := seedTestUser(t, pool)
|
|
q := dbq.New(pool)
|
|
|
|
now := time.Date(2026, 4, 25, 12, 0, 0, 0, time.UTC)
|
|
first, _ := FindOrCreate(context.Background(), q, user, now, "client-a", 30*time.Minute)
|
|
second, err := FindOrCreate(context.Background(), q, user, now.Add(30*time.Minute), "client-a", 30*time.Minute)
|
|
if err != nil {
|
|
t.Fatalf("second: %v", err)
|
|
}
|
|
if first != second {
|
|
t.Errorf("expected same session at exact boundary, got new id %v", second)
|
|
}
|
|
}
|