From 6d519797670d862b8366e08de9ff59cfbd0d8c98 Mon Sep 17 00:00:00 2001 From: Unbewohnte Date: Sun, 27 Jun 2021 13:31:45 +0300 Subject: [PATCH] =?UTF-8?q?=E2=96=B6=20Improved=20tests,=20added=20importa?= =?UTF-8?q?nt=20notices=20=E2=97=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- id3v10.go | 2 ++ id3v10_test.go | 10 +++++----- id3v11.go | 2 ++ id3v11_test.go | 7 +++---- testData/testwritev1.mp3 | Bin 128 -> 800 bytes 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/id3v10.go b/id3v10.go index 396e1de..9ccab5a 100644 --- a/id3v10.go +++ b/id3v10.go @@ -91,6 +91,8 @@ func GetID3v1Tags(rs io.ReadSeeker) (*ID3v1Tags, error) { } // Writes given ID3v1.0 tags to given io.WriteSeeker. +// NOTE: will not remove already existing ID3v1 tag if it`s present, +// use ⁕WriteToFile⁕ method if you`re working with REAL mp3 files !!! func (tags *ID3v1Tags) Write(dst io.WriteSeeker) error { dst.Seek(0, io.SeekEnd) diff --git a/id3v10_test.go b/id3v10_test.go index e87a143..8b42743 100644 --- a/id3v10_test.go +++ b/id3v10_test.go @@ -15,7 +15,7 @@ var TESTv1TAGS = &ID3v1Tags{ } func TestGetID3v1Tags(t *testing.T) { - testfile, err := os.Open("./testData/testreadv1.mp3") + testfile, err := os.OpenFile("./testData/testreadv1.mp3", os.O_CREATE|os.O_RDONLY, os.ModePerm) if err != nil { t.Errorf("could not open file for testing: %s", err) } @@ -30,9 +30,7 @@ func TestGetID3v1Tags(t *testing.T) { } func TestWriteID3v1Tags(t *testing.T) { - os.Remove("./testData/testwritev1.mp3") - - f, err := os.Create("./testData/testwritev1.mp3") + f, err := os.OpenFile("./testData/testwritev1.mp3", os.O_CREATE|os.O_RDWR, os.ModePerm) if err != nil { t.Errorf("%s", err) } @@ -40,11 +38,13 @@ func TestWriteID3v1Tags(t *testing.T) { tags := TESTv1TAGS + // writing tags err = tags.Write(f) if err != nil { t.Errorf("WriteID3v1Tags failed: %s", err) } + // reading tags readTags, err := GetID3v1Tags(f) if err != nil { t.Errorf("%s", err) @@ -60,7 +60,7 @@ func TestWriteID3v1Tags(t *testing.T) { } func TestWriteID3v1ToFile(t *testing.T) { - f, err := os.Open("./testData/testwritev1.mp3") + f, err := os.OpenFile("./testData/testwritev1.mp3", os.O_CREATE|os.O_RDWR, os.ModePerm) if err != nil { t.Errorf("%s", err) } diff --git a/id3v11.go b/id3v11.go index 49d3876..112b234 100644 --- a/id3v11.go +++ b/id3v11.go @@ -107,6 +107,8 @@ func GetID3v11Tags(rs io.ReadSeeker) (*ID3v11Tags, error) { } // Writes given ID3v1.1 tags to dst +// NOTE: will not remove already existing ID3v1.1 tag if it`s present, +// use ⁕WriteToFile⁕ method if you`re working with REAL mp3 files !!! func (tags *ID3v11Tags) Write(dst io.WriteSeeker) error { dst.Seek(0, io.SeekEnd) diff --git a/id3v11_test.go b/id3v11_test.go index 3c9674a..bf9f0c8 100644 --- a/id3v11_test.go +++ b/id3v11_test.go @@ -36,10 +36,9 @@ func TestGetID3v11Tags(t *testing.T) { } } +// WILL ADD NEW "TAG" WITHOUT REMOVING THE OLD ONE !!! func TestWriteID3v11Tags(t *testing.T) { - os.Remove("./testData/testwritev1.mp3") - - f, err := os.Create("./testData/testwritev1.mp3") + f, err := os.OpenFile("./testData/testwritev1.mp3", os.O_CREATE|os.O_RDWR, os.ModePerm) if err != nil { t.Errorf("%s", err) } @@ -71,7 +70,7 @@ func TestWriteID3v11Tags(t *testing.T) { } func TestWriteID3v11ToFile(t *testing.T) { - f, err := os.Open("./testData/testwritev1.mp3") + f, err := os.OpenFile("./testData/testwritev1.mp3", os.O_CREATE|os.O_RDWR, os.ModePerm) if err != nil { t.Errorf("%s", err) } diff --git a/testData/testwritev1.mp3 b/testData/testwritev1.mp3 index 6ed27e6ed24cadb72ba25bb14b54f4c5e2dddfed..9a44f1f33e10acf9976d4c6e4f189f692456bc96 100644 GIT binary patch literal 800 zcmeH?v2MdK3`8~aEA9h2Wy#znSqgM9kTr}&R{|ulm8cl``^cHSXDQcr?+$F51)hx& zqzYMJ!>Z+KbQ75NIfy6X;t>}-v|l}HFZk=x1dK&im^5o2u&n^J#*{Ez#@F`*UEup~ ziZhS+^m%U7o8VH1J?SYXK^6<@#}xRk(W8yY;Rn7)twh6l^=tWYySGuU7Mtzi7frXG a_nVR|NjY^Vvvvk delta 7 OcmZ3$*1$M%K?48^f&$q9