Commit 0f16221a authored by Christian Pointner's avatar Christian Pointner
Browse files

store: fix playlist tests

parent 85a1ffca
Pipeline #723 passed with stages
in 31 minutes and 59 seconds
......@@ -32,6 +32,7 @@ import (
"path/filepath"
"reflect"
"testing"
"time"
//"github.com/jinzhu/gorm"
)
......@@ -574,9 +575,14 @@ func TestFilesSourceHash(t *testing.T) {
// Playlists
//
func generateTestPlaylist(uris ...string) (p Playlist) {
for _, u := range uris {
e := PlaylistEntry{URI: u}
type playlistTestEntry struct {
uri string
duration *time.Duration
}
func generateTestPlaylist(entries ...playlistTestEntry) (p Playlist) {
for _, entry := range entries {
e := PlaylistEntry{URI: entry.uri, Duration: entry.duration}
p.Entries = append(p.Entries, e)
}
return p
......@@ -601,8 +607,14 @@ func TestPlaylistsListCreateDelete(t *testing.T) {
t.Fatalf("listing playlists of not existing show should return and empty list but ListPlaylists returned: %v", playlists)
}
in := generateTestPlaylist("audioin://1", "http://stream.example.com/live.mp")
in := generateTestPlaylist(playlistTestEntry{"audioin://1", nil}, playlistTestEntry{"http://stream.example.com/live.mp", nil})
testPlaylist, err := store.CreatePlaylist(testShowName, in)
if err != ErrPlaylistHasMultipleNullDurationEntries {
t.Fatalf("creating playlist with more than one non-file entry without duration should fail with specific error but returned: %v", err)
}
testDuration := time.Second
in = generateTestPlaylist(playlistTestEntry{"audioin://1", &testDuration}, playlistTestEntry{"http://stream.example.com/live.mp", nil})
testPlaylist, err = store.CreatePlaylist(testShowName, in)
if err != nil {
t.Fatalf("creating playlist in test show failed: %v", err)
}
......@@ -615,12 +627,12 @@ func TestPlaylistsListCreateDelete(t *testing.T) {
t.Fatalf("ListPlaylists should return a single playlist but returned: %v", playlists)
}
in1 := generateTestPlaylist("audioin://1", "http://stream.example.com/live.mp3")
in1 := generateTestPlaylist(playlistTestEntry{"audioin://1", &testDuration}, playlistTestEntry{"http://stream.example.com/live.mp3", nil})
_, err = store.CreatePlaylist(testShow1, in1)
if err != nil {
t.Fatalf("creating playlist in not existing show shouldn't throw an error but CreatePlaylist returned: %v", err)
}
in2 := generateTestPlaylist("https://stream.example.com/other.ogg", "audioin://2")
in2 := generateTestPlaylist(playlistTestEntry{"https://stream.example.com/other.ogg", &testDuration}, playlistTestEntry{"audioin://2", nil})
_, err = store.CreatePlaylist(testShow1, in2)
if err != nil {
t.Fatalf("creating playlist in not existing show shouldn't throw an error but CreatePlaylist returned: %v", err)
......@@ -667,7 +679,7 @@ func TestPlaylistsCreateAndGet(t *testing.T) {
t.Fatalf("getting playlist in not-existing show should return ErrNotFound, but GetPlaylist returned: %v", err)
}
p := generateTestPlaylist("http://stream.example.com/stream.mp3")
p := generateTestPlaylist(playlistTestEntry{"http://stream.example.com/stream.mp3", nil})
p.Entries = append(p.Entries, PlaylistEntry{File: &File{ShowName: file1.ShowName, ID: file1.ID}})
list1, err := store.CreatePlaylist(testShow1, p)
if err != nil {
......@@ -679,7 +691,7 @@ func TestPlaylistsCreateAndGet(t *testing.T) {
}
// TODO: check if playlists are equal
p = generateTestPlaylist("http://stream.example.com/other.mp3", fmt.Sprintf("file://%s/%d", file1.ShowName, file1.ID))
p = generateTestPlaylist(playlistTestEntry{"http://stream.example.com/other.mp3", nil}, playlistTestEntry{fmt.Sprintf("file://%s/%d", file1.ShowName, file1.ID), nil})
if _, err = store.CreatePlaylist(testShow1, p); err != nil {
t.Fatalf("unexpected error: %v", err)
}
......@@ -719,7 +731,7 @@ func TestFileUsage(t *testing.T) {
t.Fatalf("file should be in use by any playlist but got %d entries in usage list", len(lists))
}
p := generateTestPlaylist("http://stream.example.com/stream.mp3")
p := generateTestPlaylist(playlistTestEntry{"http://stream.example.com/stream.mp3", nil})
p.Entries = append(p.Entries, PlaylistEntry{File: &File{ShowName: file.ShowName, ID: file.ID}})
list, err := store.CreatePlaylist(testShow1, p)
if err != nil {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment