refactor(mockfs): automatically clean up with t.Cleanup()
This commit is contained in:
@@ -96,10 +96,10 @@ func runQueryCases(t *testing.T, contr *Controller, h handlerSubsonic, cases []*
|
||||
}
|
||||
}
|
||||
|
||||
func makeController(t *testing.T) (*Controller, *mockfs.MockFS) { return makec(t, []string{""}) }
|
||||
func makeControllerRoots(t *testing.T, r []string) (*Controller, *mockfs.MockFS) { return makec(t, r) }
|
||||
func makeController(t *testing.T) *Controller { return makec(t, []string{""}) }
|
||||
func makeControllerRoots(t *testing.T, r []string) *Controller { return makec(t, r) }
|
||||
|
||||
func makec(t *testing.T, roots []string) (*Controller, *mockfs.MockFS) {
|
||||
func makec(t *testing.T, roots []string) *Controller {
|
||||
t.Helper()
|
||||
|
||||
m := mockfs.NewWithDirs(t, roots)
|
||||
@@ -117,7 +117,7 @@ func makec(t *testing.T, roots []string) (*Controller, *mockfs.MockFS) {
|
||||
}
|
||||
|
||||
base := &ctrlbase.Controller{DB: m.DB()}
|
||||
return &Controller{Controller: base, MusicPaths: absRoots}, m
|
||||
return &Controller{Controller: base, MusicPaths: absRoots}
|
||||
}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
|
||||
@@ -8,8 +8,7 @@ import (
|
||||
)
|
||||
|
||||
func TestGetIndexes(t *testing.T) {
|
||||
contr, m := makeControllerRoots(t, []string{"m-0", "m-1"})
|
||||
defer m.CleanUp()
|
||||
contr := makeControllerRoots(t, []string{"m-0", "m-1"})
|
||||
|
||||
runQueryCases(t, contr, contr.ServeGetIndexes, []*queryCase{
|
||||
{url.Values{}, "no_args", false},
|
||||
@@ -19,8 +18,7 @@ func TestGetIndexes(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetMusicDirectory(t *testing.T) {
|
||||
contr, m := makeController(t)
|
||||
defer m.CleanUp()
|
||||
contr := makeController(t)
|
||||
|
||||
runQueryCases(t, contr, contr.ServeGetMusicDirectory, []*queryCase{
|
||||
{url.Values{"id": {"al-2"}}, "without_tracks", false},
|
||||
@@ -30,8 +28,7 @@ func TestGetMusicDirectory(t *testing.T) {
|
||||
|
||||
func TestGetAlbumList(t *testing.T) {
|
||||
t.Parallel()
|
||||
contr, m := makeController(t)
|
||||
defer m.CleanUp()
|
||||
contr := makeController(t)
|
||||
|
||||
runQueryCases(t, contr, contr.ServeGetAlbumList, []*queryCase{
|
||||
{url.Values{"type": {"alphabeticalByArtist"}}, "alpha_artist", false},
|
||||
@@ -43,8 +40,7 @@ func TestGetAlbumList(t *testing.T) {
|
||||
|
||||
func TestSearchTwo(t *testing.T) {
|
||||
t.Parallel()
|
||||
contr, m := makeController(t)
|
||||
defer m.CleanUp()
|
||||
contr := makeController(t)
|
||||
|
||||
runQueryCases(t, contr, contr.ServeSearchTwo, []*queryCase{
|
||||
{url.Values{"query": {"art"}}, "q_art", false},
|
||||
|
||||
@@ -7,8 +7,7 @@ import (
|
||||
|
||||
func TestGetArtists(t *testing.T) {
|
||||
t.Parallel()
|
||||
contr, m := makeControllerRoots(t, []string{"m-0", "m-1"})
|
||||
defer m.CleanUp()
|
||||
contr := makeControllerRoots(t, []string{"m-0", "m-1"})
|
||||
|
||||
runQueryCases(t, contr, contr.ServeGetArtists, []*queryCase{
|
||||
{url.Values{}, "no_args", false},
|
||||
@@ -19,8 +18,7 @@ func TestGetArtists(t *testing.T) {
|
||||
|
||||
func TestGetArtist(t *testing.T) {
|
||||
t.Parallel()
|
||||
contr, m := makeController(t)
|
||||
defer m.CleanUp()
|
||||
contr := makeController(t)
|
||||
|
||||
runQueryCases(t, contr, contr.ServeGetArtist, []*queryCase{
|
||||
{url.Values{"id": {"ar-1"}}, "id_one", false},
|
||||
@@ -31,8 +29,7 @@ func TestGetArtist(t *testing.T) {
|
||||
|
||||
func TestGetAlbum(t *testing.T) {
|
||||
t.Parallel()
|
||||
contr, m := makeController(t)
|
||||
defer m.CleanUp()
|
||||
contr := makeController(t)
|
||||
|
||||
runQueryCases(t, contr, contr.ServeGetAlbum, []*queryCase{
|
||||
{url.Values{"id": {"al-2"}}, "without_cover", false},
|
||||
@@ -42,8 +39,7 @@ func TestGetAlbum(t *testing.T) {
|
||||
|
||||
func TestGetAlbumListTwo(t *testing.T) {
|
||||
t.Parallel()
|
||||
contr, m := makeController(t)
|
||||
defer m.CleanUp()
|
||||
contr := makeController(t)
|
||||
|
||||
runQueryCases(t, contr, contr.ServeGetAlbumListTwo, []*queryCase{
|
||||
{url.Values{"type": {"alphabeticalByArtist"}}, "alpha_artist", false},
|
||||
@@ -55,8 +51,7 @@ func TestGetAlbumListTwo(t *testing.T) {
|
||||
|
||||
func TestSearchThree(t *testing.T) {
|
||||
t.Parallel()
|
||||
contr, m := makeController(t)
|
||||
defer m.CleanUp()
|
||||
contr := makeController(t)
|
||||
|
||||
runQueryCases(t, contr, contr.ServeSearchThree, []*queryCase{
|
||||
{url.Values{"query": {"art"}}, "q_art", false},
|
||||
|
||||
Reference in New Issue
Block a user