Files
minstrel/internal/subsonic/replaygain_test.go
T
bvandeusenandClaude Opus 5.5 e1f270362d
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
chore(release): everything that ships points at GitHub and GHCR (#7897)
- 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>
2026-11-28 19:28:16 -05:00

59 lines
1.8 KiB
Go

package subsonic
import (
"encoding/json"
"encoding/xml"
"strings"
"testing"
"github.com/Fabled-Sword/minstrel/internal/db/dbq"
"github.com/Fabled-Sword/minstrel/internal/library"
)
// OpenSubsonic's replayGain is an object in JSON and an element with
// attributes in XML. Clients parse both, so both are pinned.
func TestSongRef_ReplayGainEncodesForBothFormats(t *testing.T) {
gain, peak := float32(-4.5), float32(0.8913)
tr := dbq.Track{Title: "Song", FilePath: "/m/a.flac", FileFormat: "flac"}
s := songRef(tr, "Album", "Artist", library.ReplayGain{TrackGain: &gain, TrackPeak: &peak})
b, err := json.Marshal(s)
if err != nil {
t.Fatal(err)
}
var m map[string]any
if err := json.Unmarshal(b, &m); err != nil {
t.Fatal(err)
}
rg, ok := m["replayGain"].(map[string]any)
if !ok {
t.Fatalf("JSON has no replayGain object: %s", b)
}
if rg["trackGain"] != -4.5 || rg["trackPeak"] == nil {
t.Errorf("JSON replayGain = %v, want trackGain -4.5 and a trackPeak", rg)
}
if _, ok := rg["albumGain"]; ok {
t.Errorf("JSON replayGain carries albumGain with no album value: %v", rg)
}
x, err := xml.Marshal(s)
if err != nil {
t.Fatal(err)
}
if !strings.Contains(string(x), `<replayGain trackGain="-4.5" trackPeak="0.8913"></replayGain>`) {
t.Errorf("XML lacks the replayGain element: %s", x)
}
}
func TestSongRef_NoReplayGainWhenUnmeasured(t *testing.T) {
s := songRef(dbq.Track{Title: "Song", FilePath: "/m/a.mp3"}, "Album", "Artist", library.ReplayGain{})
if s.ReplayGain != nil {
t.Fatalf("unmeasured song carries replayGain %+v", s.ReplayGain)
}
b, _ := json.Marshal(s)
x, _ := xml.Marshal(s)
if strings.Contains(string(b), "replayGain") || strings.Contains(string(x), "replayGain") {
t.Errorf("unmeasured song encodes replayGain: %s / %s", b, x)
}
}