43 lines
1.2 KiB
Go
43 lines
1.2 KiB
Go
package m3u_test
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
|
|
"git.t-juice.club/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)
|
|
}
|
|
})
|
|
|
|
}
|