-
-
Notifications
You must be signed in to change notification settings - Fork 799
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
198 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package scanner2_test | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestScanner(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Scanner Suite") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package scanner2 | ||
|
||
import ( | ||
"context" | ||
"testing/fstest" | ||
|
||
"github.com/navidrome/navidrome/log" | ||
"github.com/navidrome/navidrome/model" | ||
"github.com/navidrome/navidrome/scanner" | ||
"github.com/navidrome/navidrome/tests" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("Scanner", func() { | ||
var fs FakeFS | ||
var files fstest.MapFS | ||
var ctx context.Context | ||
var libRepo tests.MockLibraryRepo | ||
var ds tests.MockDataStore | ||
var s scanner.Scanner | ||
var lib model.Library | ||
|
||
BeforeEach(func() { | ||
log.SetLevel(log.LevelTrace) | ||
ctx = context.Background() | ||
files = fstest.MapFS{} | ||
libRepo = tests.MockLibraryRepo{} | ||
ds.MockedLibrary = &libRepo | ||
s = GetInstance(ctx, &ds) | ||
RegisterFakeExtractor(fs) | ||
}) | ||
|
||
JustBeforeEach(func() { | ||
libRepo.SetData(model.Libraries{lib}) | ||
fs = FakeFS{MapFS: files} | ||
}) | ||
|
||
Describe("Scan", func() { | ||
BeforeEach(func() { | ||
lib = model.Library{Name: "The Beatles", Path: "/music/The%20Beatles"} | ||
sgtPeppers := template(_tag{"albumartist": "The Beatles", "album": "Sgt. Pepper's Lonely Hearts Club Band", "year": 1967}) | ||
files = fstest.MapFS{ | ||
"The Beatles/1967 - Sgt. Pepper's Lonely Hearts Club Band/01 - Sgt. Pepper's Lonely Hearts Club Band.mp3": sgtPeppers(track(1, "Sgt. Pepper's Lonely Hearts Club Band")), | ||
"The Beatles/1967 - Sgt. Pepper's Lonely Hearts Club Band/02 - With a Little Help from My Friends.mp3": sgtPeppers(track(2, "With a Little Help from My Friends")), | ||
"The Beatles/1967 - Sgt. Pepper's Lonely Hearts Club Band/03 - Lucy in the Sky with Diamonds.mp3": sgtPeppers(track(3, "Lucy in the Sky with Diamonds")), | ||
"The Beatles/1967 - Sgt. Pepper's Lonely Hearts Club Band/04 - Getting Better.mp3": sgtPeppers(track(4, "Getting Better")), | ||
} | ||
}) | ||
|
||
It("should scan all files", func() { | ||
err := s.RescanAll(context.Background(), true) | ||
Expect(err).ToNot(HaveOccurred()) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package tests | ||
|
||
import ( | ||
"github.com/navidrome/navidrome/model" | ||
"golang.org/x/exp/maps" | ||
) | ||
|
||
type MockLibraryRepo struct { | ||
model.LibraryRepository | ||
data map[int]model.Library | ||
Err error | ||
} | ||
|
||
func (m *MockLibraryRepo) SetData(data model.Libraries) { | ||
m.data = make(map[int]model.Library) | ||
for _, d := range data { | ||
m.data[d.ID] = d | ||
} | ||
} | ||
|
||
func (m *MockLibraryRepo) GetAll(...model.QueryOptions) (model.Libraries, error) { | ||
if m.Err != nil { | ||
return nil, m.Err | ||
} | ||
return maps.Values(m.data), nil | ||
} | ||
|
||
var _ model.LibraryRepository = &MockLibraryRepo{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters