about summary refs log tree commit diff
path: root/tools/mpd-stats
diff options
context:
space:
mode:
authorFranck Cuny <franck@fcuny.net>2021-10-10 13:22:14 -0700
committerFranck Cuny <franck@fcuny.net>2022-06-11 14:32:08 -0700
commitd42e637c398b38f26de814debe6b8ee4e938664c (patch)
treecfdde1c92162261a60f5865cdab5eb625dd71b8a /tools/mpd-stats
parentmpd-stats: pass database path to the scrobbler (diff)
downloadworld-d42e637c398b38f26de814debe6b8ee4e938664c.tar.gz
record: add some basic testing
Diffstat (limited to 'tools/mpd-stats')
-rw-r--r--tools/mpd-stats/internal/scrobbler/record.go6
-rw-r--r--tools/mpd-stats/internal/scrobbler/record_test.go53
2 files changed, 59 insertions, 0 deletions
diff --git a/tools/mpd-stats/internal/scrobbler/record.go b/tools/mpd-stats/internal/scrobbler/record.go
index b9f95a0..e252fd3 100644
--- a/tools/mpd-stats/internal/scrobbler/record.go
+++ b/tools/mpd-stats/internal/scrobbler/record.go
@@ -34,3 +34,9 @@ func NewRecord(attrs mpd.Attrs) (*Record, error) {
 	record.Duration = time.Second * time.Duration(dur)
 	return &record, nil
 }
+
+func (r *Record) EqualAttrs(attrs mpd.Attrs) bool {
+	return r.Title == attrs["Title"] &&
+		r.Album == attrs["Album"] &&
+		r.Artist == attrs["Artist"]
+}
diff --git a/tools/mpd-stats/internal/scrobbler/record_test.go b/tools/mpd-stats/internal/scrobbler/record_test.go
new file mode 100644
index 0000000..3bf8554
--- /dev/null
+++ b/tools/mpd-stats/internal/scrobbler/record_test.go
@@ -0,0 +1,53 @@
+package scrobbler
+
+import (
+	"testing"
+
+	"github.com/fhs/gompd/v2/mpd"
+)
+
+func TestNewRecord(t *testing.T) {
+	song := mpd.Attrs{
+		"Artist":   "Nine Inch Nails",
+		"Album":    "The Downward Spiral",
+		"Title":    "Reptile",
+		"duration": "411.00",
+	}
+
+	record, err := NewRecord(song)
+	if err != nil {
+		t.Errorf("NewRecord returned an error: %s", err)
+	}
+	if record == nil {
+		t.Errorf("NewRecord returned nil record")
+	}
+}
+
+func TestRecordEqualAttrs(t *testing.T) {
+	s1 := mpd.Attrs{
+		"Artist":   "Nine Inch Nails",
+		"Album":    "The Downward Spiral",
+		"Title":    "Reptile",
+		"duration": "411.00",
+	}
+
+	s2 := mpd.Attrs{
+		"Artist":   "Nine Inch Nails",
+		"Album":    "The Downward Spiral",
+		"Title":    "Closer",
+		"duration": "373.00",
+	}
+
+	r, err := NewRecord(s1)
+	if err != nil {
+		t.Errorf("NewRecord returned an error: %s", err)
+	}
+
+	if !r.EqualAttrs(s1) {
+		t.Errorf("EqualAttrs expected true got false")
+	}
+
+	if r.EqualAttrs(s2) {
+		t.Errorf("EqualAttrs expected false got true")
+	}
+}