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>
70 lines
2.5 KiB
Go
70 lines
2.5 KiB
Go
package library
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"testing"
|
|
|
|
"github.com/Fabled-Sword/minstrel/internal/db/dbq"
|
|
"github.com/Fabled-Sword/minstrel/internal/dbtest"
|
|
)
|
|
|
|
func TestNormalizationPrefs_Validate(t *testing.T) {
|
|
if err := DefaultNormalizationPrefs.Validate(); err != nil {
|
|
t.Fatalf("the defaults are invalid: %v", err)
|
|
}
|
|
for _, p := range []NormalizationPrefs{
|
|
{Mode: "loud", TargetLUFS: -18, Boost: "headroom"},
|
|
{Mode: "auto", TargetLUFS: -23, Boost: "headroom"},
|
|
{Mode: "auto", TargetLUFS: -18, Boost: "max"},
|
|
// A field left out of a PUT body decodes as its zero value.
|
|
{Mode: "auto", Boost: "headroom"},
|
|
} {
|
|
if err := p.Validate(); !errors.Is(err, ErrNormalizationPrefsInvalid) {
|
|
t.Errorf("%+v: err = %v, want ErrNormalizationPrefsInvalid", p, err)
|
|
}
|
|
}
|
|
}
|
|
|
|
// A user with no row gets the Go defaults, and a stored row reads back the
|
|
// migration's defaults for any column the insert left out; the two must
|
|
// agree, or a user would hear a different level after their first save.
|
|
func TestNormalizationPrefs_DefaultsAndRoundTrip_Integration(t *testing.T) {
|
|
pool := dbtest.Pool(t)
|
|
ctx := context.Background()
|
|
q := dbq.New(pool)
|
|
user, err := q.CreateUser(ctx, dbq.CreateUserParams{
|
|
Username: dbtest.TestUserPrefix + "norm-prefs", PasswordHash: "x", ApiTokenHash: "norm-prefs-token",
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("user: %v", err)
|
|
}
|
|
|
|
got, err := LoadNormalizationPrefs(ctx, q, user.ID)
|
|
if err != nil || got != DefaultNormalizationPrefs {
|
|
t.Fatalf("unset prefs = %+v, %v; want the defaults", got, err)
|
|
}
|
|
|
|
if _, err := pool.Exec(ctx, "INSERT INTO user_normalization_prefs (user_id) VALUES ($1)", user.ID); err != nil {
|
|
t.Fatalf("insert defaults row: %v", err)
|
|
}
|
|
got, err = LoadNormalizationPrefs(ctx, q, user.ID)
|
|
if err != nil || got != DefaultNormalizationPrefs {
|
|
t.Errorf("migration defaults = %+v, Go defaults = %+v (err %v)", got, DefaultNormalizationPrefs, err)
|
|
}
|
|
|
|
want := NormalizationPrefs{Mode: "track", TargetLUFS: -14, Boost: "limiter"}
|
|
if saved, err := SaveNormalizationPrefs(ctx, q, user.ID, want); err != nil || saved != want {
|
|
t.Fatalf("save = %+v, %v; want %+v", saved, err, want)
|
|
}
|
|
if got, _ := LoadNormalizationPrefs(ctx, q, user.ID); got != want {
|
|
t.Errorf("after save = %+v, want %+v", got, want)
|
|
}
|
|
if _, err := SaveNormalizationPrefs(ctx, q, user.ID, NormalizationPrefs{Mode: "x"}); !errors.Is(err, ErrNormalizationPrefsInvalid) {
|
|
t.Errorf("invalid save: err = %v", err)
|
|
}
|
|
if got, _ := LoadNormalizationPrefs(ctx, q, user.ID); got != want {
|
|
t.Errorf("an invalid save changed the stored prefs to %+v", got)
|
|
}
|
|
}
|