From 1490e9c1e6702dfb54c62af34bfbdf61fcc06f7b Mon Sep 17 00:00:00 2001 From: Kendall Garner <17521368+kgarner7@users.noreply.github.com> Date: Sat, 9 Mar 2024 18:08:49 -0800 Subject: [PATCH] local > lrclib, do not duplicate local, test --- conf/configuration.go | 2 +- core/agents/agents.go | 13 ++++++++++++- core/agents/agents_test.go | 24 ++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/conf/configuration.go b/conf/configuration.go index eb2d233c..5ce3aef0 100644 --- a/conf/configuration.go +++ b/conf/configuration.go @@ -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", "") diff --git a/core/agents/agents.go b/core/agents/agents.go index b2c7ff63..dd70d2e3 100644 --- a/core/agents/agents.go +++ b/core/agents/agents.go @@ -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] diff --git a/core/agents/agents_test.go b/core/agents/agents_test.go index 33687048..efe556d3 100644 --- a/core/agents/agents_test.go +++ b/core/agents/agents_test.go @@ -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