Browse Source

▶ Improved tests, added important notices ◀

main
Unbewohnte 3 years ago
parent
commit
6d51979767
  1. 2
      id3v10.go
  2. 10
      id3v10_test.go
  3. 2
      id3v11.go
  4. 7
      id3v11_test.go
  5. BIN
      testData/testwritev1.mp3

2
id3v10.go

@ -91,6 +91,8 @@ func GetID3v1Tags(rs io.ReadSeeker) (*ID3v1Tags, error) {
} }
// Writes given ID3v1.0 tags to given io.WriteSeeker. // 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 { func (tags *ID3v1Tags) Write(dst io.WriteSeeker) error {
dst.Seek(0, io.SeekEnd) dst.Seek(0, io.SeekEnd)

10
id3v10_test.go

@ -15,7 +15,7 @@ var TESTv1TAGS = &ID3v1Tags{
} }
func TestGetID3v1Tags(t *testing.T) { 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 { if err != nil {
t.Errorf("could not open file for testing: %s", err) t.Errorf("could not open file for testing: %s", err)
} }
@ -30,9 +30,7 @@ func TestGetID3v1Tags(t *testing.T) {
} }
func TestWriteID3v1Tags(t *testing.T) { func TestWriteID3v1Tags(t *testing.T) {
os.Remove("./testData/testwritev1.mp3") f, err := os.OpenFile("./testData/testwritev1.mp3", os.O_CREATE|os.O_RDWR, os.ModePerm)
f, err := os.Create("./testData/testwritev1.mp3")
if err != nil { if err != nil {
t.Errorf("%s", err) t.Errorf("%s", err)
} }
@ -40,11 +38,13 @@ func TestWriteID3v1Tags(t *testing.T) {
tags := TESTv1TAGS tags := TESTv1TAGS
// writing tags
err = tags.Write(f) err = tags.Write(f)
if err != nil { if err != nil {
t.Errorf("WriteID3v1Tags failed: %s", err) t.Errorf("WriteID3v1Tags failed: %s", err)
} }
// reading tags
readTags, err := GetID3v1Tags(f) readTags, err := GetID3v1Tags(f)
if err != nil { if err != nil {
t.Errorf("%s", err) t.Errorf("%s", err)
@ -60,7 +60,7 @@ func TestWriteID3v1Tags(t *testing.T) {
} }
func TestWriteID3v1ToFile(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 { if err != nil {
t.Errorf("%s", err) t.Errorf("%s", err)
} }

2
id3v11.go

@ -107,6 +107,8 @@ func GetID3v11Tags(rs io.ReadSeeker) (*ID3v11Tags, error) {
} }
// Writes given ID3v1.1 tags to dst // 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 { func (tags *ID3v11Tags) Write(dst io.WriteSeeker) error {
dst.Seek(0, io.SeekEnd) dst.Seek(0, io.SeekEnd)

7
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) { func TestWriteID3v11Tags(t *testing.T) {
os.Remove("./testData/testwritev1.mp3") f, err := os.OpenFile("./testData/testwritev1.mp3", os.O_CREATE|os.O_RDWR, os.ModePerm)
f, err := os.Create("./testData/testwritev1.mp3")
if err != nil { if err != nil {
t.Errorf("%s", err) t.Errorf("%s", err)
} }
@ -71,7 +70,7 @@ func TestWriteID3v11Tags(t *testing.T) {
} }
func TestWriteID3v11ToFile(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 { if err != nil {
t.Errorf("%s", err) t.Errorf("%s", err)
} }

BIN
testData/testwritev1.mp3

Binary file not shown.
Loading…
Cancel
Save