local > lrclib, do not duplicate local, test

This commit is contained in:
Kendall Garner 2024-03-09 18:08:49 -08:00
parent 8d284baa4e
commit 1490e9c1e6
No known key found for this signature in database
GPG Key ID: 18D2767419676C87
3 changed files with 37 additions and 2 deletions

View File

@ -336,7 +336,7 @@ func init() {
viper.SetDefault("scanner.genreseparators", ";/,")
viper.SetDefault("scanner.groupalbumreleases", false)
viper.SetDefault("agents", "lastfm,spotify,lrclib")
viper.SetDefault("agents", "lastfm,spotify,local,lrclib")
viper.SetDefault("lastfm.enabled", true)
viper.SetDefault("lastfm.language", "en")
viper.SetDefault("lastfm.apikey", "")

View File

@ -22,7 +22,18 @@ func New(ds model.DataStore) *Agents {
if conf.Server.Agents != "" {
order = strings.Split(conf.Server.Agents, ",")
}
order = append(order, LocalAgentName)
hasLocal := false
for _, agent := range order {
if agent == LocalAgentName {
hasLocal = true
break
}
}
if !hasLocal {
order = append(order, LocalAgentName)
}
var res []Interface
for _, name := range order {
init, ok := Map[name]

View File

@ -39,6 +39,30 @@ var _ = Describe("Agents", func() {
})
})
Describe("Settings", func() {
It("does not duplicate local agent", func() {
conf.Server.Agents = LocalAgentName
ag := New(ds)
Expect(ag.agents).To(HaveLen(1))
Expect(ag.agents[0].AgentName()).To(Equal(LocalAgentName))
})
It("uses orders local correctly", func() {
for _, agent := range []string{"lastfm", "spotify", "lrclib"} {
Register(agent, func(ds model.DataStore) Interface {
return struct {
Interface
}{}
})
}
conf.Server.Agents = "lastfm,spotify,local,lrclib"
ag := New(ds)
Expect(ag.agents).To(HaveLen(4))
Expect(ag.agents[2].AgentName()).To(Equal(LocalAgentName))
})
})
Describe("Agents", func() {
var ag *Agents
var mock *mockAgent