navidrome/scanner/importer_test.go

75 lines
1.8 KiB
Go
Raw Normal View History

package scanner
2016-03-01 18:43:55 +01:00
import (
2016-03-02 19:18:39 +01:00
"testing"
2017-04-01 15:47:14 +02:00
"github.com/cloudsonic/sonic-server/domain"
"github.com/cloudsonic/sonic-server/tests"
"github.com/cloudsonic/sonic-server/utils"
. "github.com/smartystreets/goconvey/convey"
2016-03-01 18:43:55 +01:00
)
2016-03-01 23:50:05 +01:00
func TestCollectIndex(t *testing.T) {
tests.Init(t, false)
2016-03-02 19:18:39 +01:00
ig := utils.IndexGroups{"A": "A", "B": "B", "Tom": "Tom", "X": "X-Z"}
2016-03-01 18:43:55 +01:00
importer := &Importer{}
2016-03-01 23:50:05 +01:00
Convey("Simple Name", t, func() {
2016-03-02 15:07:24 +01:00
a := &domain.Artist{Name: "Björk"}
2016-03-01 23:50:05 +01:00
artistIndex := make(map[string]tempIndex)
importer.collectIndex(ig, a, artistIndex)
2016-03-01 23:50:05 +01:00
So(artistIndex, ShouldContainKey, "B")
So(artistIndex["B"], ShouldContainKey, "björk")
for _, k := range []string{"A", "Tom", "X-Z", "#"} {
So(artistIndex, ShouldNotContainKey, k)
}
})
Convey("Name not in the index", t, func() {
2016-03-02 15:07:24 +01:00
a := &domain.Artist{Name: "Kraftwerk"}
2016-03-01 23:50:05 +01:00
artistIndex := make(map[string]tempIndex)
importer.collectIndex(ig, a, artistIndex)
2016-03-01 23:50:05 +01:00
So(artistIndex, ShouldContainKey, "#")
So(artistIndex["#"], ShouldContainKey, "kraftwerk")
for _, k := range []string{"A", "B", "Tom", "X-Z"} {
So(artistIndex, ShouldNotContainKey, k)
}
})
Convey("Name starts with an article", t, func() {
2016-03-02 15:07:24 +01:00
a := &domain.Artist{Name: "The The"}
2016-03-01 23:50:05 +01:00
artistIndex := make(map[string]tempIndex)
importer.collectIndex(ig, a, artistIndex)
2016-03-01 23:50:05 +01:00
So(artistIndex, ShouldContainKey, "#")
So(artistIndex["#"], ShouldContainKey, "the")
for _, k := range []string{"A", "B", "Tom", "X-Z"} {
So(artistIndex, ShouldNotContainKey, k)
}
})
Convey("Name match a multichar entry", t, func() {
2016-03-02 15:07:24 +01:00
a := &domain.Artist{Name: "Tom Waits"}
2016-03-01 23:50:05 +01:00
artistIndex := make(map[string]tempIndex)
importer.collectIndex(ig, a, artistIndex)
2016-03-01 23:50:05 +01:00
So(artistIndex, ShouldContainKey, "Tom")
So(artistIndex["Tom"], ShouldContainKey, "tom waits")
for _, k := range []string{"A", "B", "X-Z", "#"} {
So(artistIndex, ShouldNotContainKey, k)
}
})
}