Skip to content

Commit

Permalink
Add test for custom tagger / pathers.
Browse files Browse the repository at this point in the history
  • Loading branch information
joshkunz committed Oct 11, 2021
1 parent 2dac16d commit d156c3f
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions library/library_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,68 @@ func TestLetterName(t *testing.T) {
}
}
}

func TestCustomTagger(t *testing.T) {
want := trackInfo{
Artist: "Custom Artist",
Album: "Custom Album",
Title: "Custom Title",
}

tagF := func(idx int) *id3v2.Tag {
t := id3v2.NewEmptyTag()
t.SetArtist(want.Artist)
t.SetAlbum(want.Album)
t.SetTitle(want.Title)
return t
}

lib, err := New(bytes.NewReader(nil))
if err != nil {
t.Fatalf("Failed to create new library: %v", err)
}
lib.Tagger = tagF

gotSong, err := lib.SongAt(0)
if err != nil {
t.Fatalf("lib.SongAt(0) = %v", err)
}
got, err := songInfo(gotSong)
if err != nil {
t.Fatalf("songInfo(...) = _, %v, want _, nil", err)
}

if diff := cmp.Diff(want, got); diff != "" {
t.Errorf("lib.SongAt(0) had unexpected diff (want -> got):\n%s", diff)
}
}

func TestCustomPather(t *testing.T) {
wantTag := id3v2.NewEmptyTag()
const want = "abc.mp3"

lib, err := New(bytes.NewReader(nil))
if err != nil {
t.Fatalf("Failed to create new library: %v", err)
}
lib.Tagger = func(int) *id3v2.Tag {
return wantTag
}
lib.Pather = func(_ int, gotTag *id3v2.Tag) string {
// Need to make sure that the pather is passed the tag from the
// tagger.
if wantTag != gotTag {
t.Errorf("Pather got unexpected tag %v, want %v", gotTag, wantTag)
}
return want
}

got, err := lib.PathAt(0)
if err != nil {
t.Fatalf("lib.PathAt(0) = _, %v; want _, nil", err)
}

if got != want {
t.Errorf("lib.PathAt(0) = %q, want %q", got, want)
}
}

0 comments on commit d156c3f

Please sign in to comment.