Skip to content
Snippets Groups Projects
Commit 58a3a0ba authored by Christian Pointner's avatar Christian Pointner
Browse files

some more test cases

parent de773386
No related branches found
No related tags found
No related merge requests found
...@@ -688,3 +688,62 @@ func TestPlaylistsCreateAndGet(t *testing.T) { ...@@ -688,3 +688,62 @@ func TestPlaylistsCreateAndGet(t *testing.T) {
} }
// TODO: check playlists contains both lists // TODO: check playlists contains both lists
} }
// File usage
//
func TestFileUsage(t *testing.T) {
store := newTestStore(t)
file := &File{Size: 12345}
file.Source.URI = testSourceURI1
file.Metadata.Artist = testFileArtist1
file.Metadata.Album = testFileAlbum1
file.Metadata.Title = testFileTitle1
file, err := store.CreateFile(testShow1, *file)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
lists, err := store.GetFileUsage(file.ShowName, file.ID)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if len(lists) != 0 {
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.Entries = append(p.Entries, PlaylistEntry{File: &File{ShowName: file.ShowName, ID: file.ID}})
list, err := store.CreatePlaylist(testShow1, p)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
lists, err = store.GetFileUsage(file.ShowName, file.ID)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if len(lists) != 1 {
t.Fatalf("file should be used by exactly one playlist but got %d entries in usage list", len(lists))
}
if lists[0].ID != list.ID {
t.Fatalf("file should be in use by playlist %d but entries of usage list only contains: %d", list.ID, lists[0].ID)
}
err = store.DeleteFile(file.ShowName, file.ID)
errInUse, ok := err.(*ErrFileInUse)
if !ok {
t.Fatalf("deleting file that is in use should return an error of type ErrFileInUs, but returned: %v (type: %t)", err, err)
}
if len(errInUse.Playlists) != 1 || errInUse.Playlists[0].ID != list.ID {
t.Fatalf("usage reports invalid playlist-list: %+v", errInUse.Playlists)
}
if err = store.DeletePlaylist(list.ShowName, list.ID); err != nil {
t.Fatalf("unexpected error: %v", err)
}
if err = store.DeleteFile(file.ShowName, file.ID); err != nil {
t.Fatalf("unexpected error: %v", err)
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment