🎧 Your Personal Streaming Service
Go airsonicmadsonicmedia-servermusicmusic-servernavidromeopensubsonicraspberry-piself-hostedstreamerstreaming-apistreaming-audiosubsonicsubsonic-server
test: enable Subsonic response snapshot tests on Windows (#5427)
Deluan Quintão3e25ca38684d
diff --git a/go.mod b/go.modindex b7dbb9eeb..b1d7d3516 100644--- a/go.mod+++ b/go.mod@@ -9,7 +9,6 @@ require (github.com/Masterminds/squirrel v1.5.4github.com/andybalholm/cascadia v1.3.3github.com/bmatcuk/doublestar/v4 v4.10.0- github.com/bradleyjkemp/cupaloy/v2 v2.8.0github.com/deluan/rest v0.0.0-20211102003136-6260bc399cbfgithub.com/deluan/sanitize v0.0.0-20241120162836-fdfd8fdfaa55github.com/dexterlb/mpvipc v0.0.0-20241005113212-7cdefca0e933@@ -42,6 +41,7 @@ require (github.com/onsi/ginkgo/v2 v2.28.1github.com/onsi/gomega v1.39.1github.com/pelletier/go-toml/v2 v2.3.0+ github.com/pmezard/go-difflib v1.0.0github.com/pocketbase/dbx v1.12.0github.com/pressly/goose/v3 v3.27.0github.com/prometheus/client_golang v1.23.2@@ -112,7 +112,6 @@ require (github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirectgithub.com/ogier/pflag v0.0.1 // indirectgithub.com/pkg/errors v0.9.1 // indirect- github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirectgithub.com/prometheus/client_model v0.6.2 // indirectgithub.com/prometheus/common v0.67.5 // indirectgithub.com/prometheus/procfs v0.19.2 // indirectdiff --git a/go.sum b/go.sumindex 29b979413..6ce31dc22 100644--- a/go.sum+++ b/go.sum@@ -16,8 +16,6 @@ github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=github.com/bmatcuk/doublestar/v4 v4.10.0 h1:zU9WiOla1YA122oLM6i4EXvGW62DvKZVxIe6TYWexEs=github.com/bmatcuk/doublestar/v4 v4.10.0/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc=-github.com/bradleyjkemp/cupaloy/v2 v2.8.0 h1:any4BmKE+jGIaMpnU8YgH/I2LPiLBufr6oMMlVBbn9M=-github.com/bradleyjkemp/cupaloy/v2 v2.8.0/go.mod h1:bm7JXdkRd4BHJk9HpwqAI8BoAY1lps46Enkdqw6aRX0=github.com/cespare/reflex v0.3.1 h1:N4Y/UmRrjwOkNT0oQQnYsdr6YBxvHqtSfPB4mqOyAKk=github.com/cespare/reflex v0.3.1/go.mod h1:I+0Pnu2W693i7Hv6ZZG76qHTY0mgUa7uCIfCtikXojE=github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=@@ -205,9 +203,8 @@ github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKgithub.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=+github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=-github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=-github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=github.com/pocketbase/dbx v1.12.0 h1:/oLErM+A0b4xI0PWTGPqSDVjzix48PqI/bng2l0PzoA=github.com/pocketbase/dbx v1.12.0/go.mod h1:xXRCIAKTHMgUCyCKZm55pUOdvFziJjQfXaWKhu2vhMs=github.com/pressly/goose/v3 v3.27.0 h1:/D30gVTuQhu0WsNZYbJi4DMOsx1lNq+6SkLe+Wp59BM=diff --git a/server/subsonic/responses/.snapshots/.gitattributes b/server/subsonic/responses/.snapshots/.gitattributesnew file mode 100644index 000000000..44b4224b1--- /dev/null+++ b/server/subsonic/responses/.snapshots/.gitattributes@@ -0,0 +1 @@+* eol=lf\ No newline at end of filediff --git a/server/subsonic/responses/responses_suite_test.go b/server/subsonic/responses/responses_suite_test.goindex e10957af2..7fc10aa15 100644--- a/server/subsonic/responses/responses_suite_test.go+++ b/server/subsonic/responses/responses_suite_test.go@@ -1,14 +1,17 @@package responsesimport (+ "fmt"+ "os"+ "path/filepath""strings""testing"- "github.com/bradleyjkemp/cupaloy/v2""github.com/navidrome/navidrome/log""github.com/onsi/ginkgo/v2""github.com/onsi/gomega""github.com/onsi/gomega/types"+ "github.com/pmezard/go-difflib/difflib")func TestSubsonicApiResponses(t *testing.T) {@@ -18,25 +21,61 @@ func TestSubsonicApiResponses(t *testing.T) {}func MatchSnapshot() types.GomegaMatcher {- c := cupaloy.New(cupaloy.FailOnUpdate(false))- return &snapshotMatcher{c}+ return &snapshotMatcher{}}type snapshotMatcher struct {- c *cupaloy.Config+ diff string}-func (matcher snapshotMatcher) Match(actual any) (success bool, err error) {- actualJson := strings.TrimSpace(string(actual.([]byte)))- err = matcher.c.SnapshotWithName(ginkgo.CurrentSpecReport().FullText(), actualJson)- success = err == nil- return+func (matcher *snapshotMatcher) Match(actual any) (success bool, err error) {+ actualBytes, ok := actual.([]byte)+ if !ok {+ return false, fmt.Errorf("MatchSnapshot expects []byte, got %T", actual)+ }++ name := ginkgo.CurrentSpecReport().FullText()+ actualStr := strings.TrimSpace(string(actualBytes))++ snapshotPath := filepath.Join(".snapshots", name)++ // Support UPDATE_SNAPSHOTS=true for `make snapshots`+ if _, update := os.LookupEnv("UPDATE_SNAPSHOTS"); update {+ err := os.MkdirAll(".snapshots", os.ModePerm)+ if err != nil {+ return false, err+ }+ return true, os.WriteFile(snapshotPath, []byte(actualStr+"\n"), 0600)+ }++ expected, err := os.ReadFile(snapshotPath)+ if err != nil {+ return false, err+ }++ // Normalize line endings so snapshots work on Windows (CRLF) and Unix (LF)+ normalizedExpected := strings.ReplaceAll(string(expected), "\r\n", "\n")+ normalizedExpected = strings.TrimSpace(normalizedExpected)++ if actualStr == normalizedExpected {+ return true, nil+ }++ diff, _ := difflib.GetUnifiedDiffString(difflib.UnifiedDiff{+ A: difflib.SplitLines(normalizedExpected),+ B: difflib.SplitLines(actualStr),+ FromFile: "snapshot",+ ToFile: "actual",+ Context: 3,+ })+ matcher.diff = diff+ return false, nil}-func (matcher snapshotMatcher) FailureMessage(_ any) (message string) {- return "Expected to match saved snapshot\n"+func (matcher *snapshotMatcher) FailureMessage(_ any) (message string) {+ return "Expected to match saved snapshot\n" + matcher.diff}-func (matcher snapshotMatcher) NegatedFailureMessage(_ any) (message string) {+func (matcher *snapshotMatcher) NegatedFailureMessage(_ any) (message string) {return "Expected to not match saved snapshot\n"}diff --git a/server/subsonic/responses/responses_test.go b/server/subsonic/responses/responses_test.goindex 9910ced14..ba86deaf2 100644--- a/server/subsonic/responses/responses_test.go+++ b/server/subsonic/responses/responses_test.go@@ -1,8 +1,3 @@-//go:build unix--// TODO Fix snapshot tests in Windows-// Response Snapshot tests. Only run in Linux and macOS, as they fail in Windows-// Probably because of EOL char differencespackage responses_testimport (