From 5dfd11d2c984beb744141bb9b114115fea7cd18f Mon Sep 17 00:00:00 2001 From: jo Date: Sat, 22 Sep 2018 20:46:59 +0200 Subject: [PATCH] Add FileType and Format testing --- tag_test.go | 54 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 19 deletions(-) diff --git a/tag_test.go b/tag_test.go index c80211e..0b79003 100644 --- a/tag_test.go +++ b/tag_test.go @@ -50,25 +50,37 @@ var mp3id3v11Metadata = testMetadata{ Year: 2000, } +type testData struct { + testMetadata + FileType + Format +} + func TestReadFrom(t *testing.T) { - testdata := map[string]testMetadata{ - "with_tags/sample.flac": fullMetadata, - "with_tags/sample.id3v11.mp3": mp3id3v11Metadata, - "with_tags/sample.id3v22.mp3": fullMetadata, - "with_tags/sample.id3v23.mp3": fullMetadata, - "with_tags/sample.id3v24.mp3": fullMetadata, - "with_tags/sample.m4a": fullMetadata, - "with_tags/sample.mp4": fullMetadata, - "with_tags/sample.ogg": fullMetadata, - "without_tags/sample.flac": emptyMetadata, - "without_tags/sample.m4a": emptyMetadata, - "without_tags/sample.mp3": emptyMetadata, - "without_tags/sample.mp4": emptyMetadata, - "without_tags/sample.ogg": emptyMetadata, + testdata := map[string]testData{ + "with_tags/sample.flac": {fullMetadata, FLAC, VORBIS}, + "with_tags/sample.id3v11.mp3": {mp3id3v11Metadata, MP3, ID3v1}, + // TODO: Convert sample.id3v22.mp3 file to ID3v2.2 tag format + "with_tags/sample.id3v22.mp3": {fullMetadata, MP3, ID3v2_3}, + "with_tags/sample.id3v23.mp3": {fullMetadata, MP3, ID3v2_3}, + "with_tags/sample.id3v24.mp3": {fullMetadata, MP3, ID3v2_4}, + // TODO: Detect correct file type + "with_tags/sample.m4a": {fullMetadata, UnknownFileType, MP4}, + // TODO: Detect correct file type + "with_tags/sample.mp4": {fullMetadata, UnknownFileType, MP4}, + "with_tags/sample.ogg": {fullMetadata, OGG, VORBIS}, + + "without_tags/sample.flac": {emptyMetadata, FLAC, VORBIS}, + // TODO: Detect correct file type + "without_tags/sample.m4a": {emptyMetadata, UnknownFileType, MP4}, + "without_tags/sample.mp3": {emptyMetadata, MP3, UnknownFormat}, + // TODO: Detect correct file type + "without_tags/sample.mp4": {emptyMetadata, UnknownFileType, MP4}, + "without_tags/sample.ogg": {emptyMetadata, OGG, VORBIS}, } - for path, metadata := range testdata { - if err := test(t, path, metadata); err != nil { + for path, data := range testdata { + if err := test(t, path, data); err != nil { // mp3 id3v11 returns an err if it doesn't find any tags if err != ErrNoTagsFound && path != "without_tags/sample.mp3" { @@ -79,7 +91,8 @@ func TestReadFrom(t *testing.T) { } } -func test(t *testing.T, path string, metadata testMetadata) error { +func test(t *testing.T, path string, data testData) error { + t.Log("testing '" + path + "'") f, err := os.Open("testdata/" + path) if err != nil { return err @@ -90,11 +103,11 @@ func test(t *testing.T, path string, metadata testMetadata) error { if err != nil { return err } - compareMetadata(t, m, metadata) + compareMetadata(t, m, data) return nil } -func compareMetadata(t *testing.T, m Metadata, tt testMetadata) { +func compareMetadata(t *testing.T, m Metadata, tt testData) { testValue(t, tt.Album, m.Album()) testValue(t, tt.AlbumArtist, m.AlbumArtist()) testValue(t, tt.Artist, m.Artist()) @@ -111,6 +124,9 @@ func compareMetadata(t *testing.T, m Metadata, tt testMetadata) { track, trackTotal := m.Track() testValue(t, tt.Track, track) testValue(t, tt.TrackTotal, trackTotal) + + testValue(t, tt.Format, m.Format()) + testValue(t, tt.FileType, m.FileType()) } func testValue(t *testing.T, expected interface{}, found interface{}) {