dogtamer/m3u/m3u_test.go

43 lines
1.2 KiB
Go
Raw Normal View History

2021-09-14 20:51:36 +00:00
package m3u_test
import (
"bytes"
"testing"
"github.uio.no/torjus/dogtamer/m3u"
)
func TestPlaylist(t *testing.T) {
t.Run("TestWriteSingle", func(t *testing.T) {
var p m3u.Playlist
p.Add(&m3u.PlaylistItem{Name: "TestItem", Path: "rtmp://localhost:5566/view/test", Time: -1})
var buf bytes.Buffer
_, err := p.WriteTo(&buf)
if err != nil {
t.Fatalf("Unable to write playlist: %s", err)
}
expected := "#EXTM3U\n#EXTINF:-1,TestItem\nrtmp://localhost:5566/view/test"
if buf.String() != expected {
t.Errorf("Output does not match expected. Got '%s' want '%s'", buf.String(), expected)
}
})
t.Run("TestWriteMultiple", func(t *testing.T) {
var p m3u.Playlist
p.Add(&m3u.PlaylistItem{Name: "TestItem", Path: "rtmp://localhost:5566/view/test", Time: -1})
p.Add(&m3u.PlaylistItem{Name: "TestTwo", Path: "rtmp://localhost:5566/view/testtwo", Time: 5})
var buf bytes.Buffer
_, err := p.WriteTo(&buf)
if err != nil {
t.Fatalf("Unable to write playlist: %s", err)
}
expected := "#EXTM3U\n#EXTINF:-1,TestItem\nrtmp://localhost:5566/view/test\n#EXTINF:5,TestTwo\nrtmp://localhost:5566/view/testtwo"
if buf.String() != expected {
t.Errorf("Output does not match expected. Got '%s' want '%s'", buf.String(), expected)
}
})
}