mirror of
https://git.sr.ht/~phw/scotty
synced 2025-04-30 05:37:05 +02:00
Renamed Backend.FromConfig to Backend.InitConfig and added error handling
This commit is contained in:
parent
aad542850a
commit
0f4b04c641
21 changed files with 60 additions and 48 deletions
|
@ -52,7 +52,7 @@ func (b *SubsonicApiBackend) Options() []models.BackendOption {
|
|||
}}
|
||||
}
|
||||
|
||||
func (b *SubsonicApiBackend) FromConfig(config *config.ServiceConfig) models.Backend {
|
||||
func (b *SubsonicApiBackend) InitConfig(config *config.ServiceConfig) error {
|
||||
b.client = subsonic.Client{
|
||||
Client: &http.Client{},
|
||||
BaseUrl: config.GetString("server-url"),
|
||||
|
@ -60,7 +60,7 @@ func (b *SubsonicApiBackend) FromConfig(config *config.ServiceConfig) models.Bac
|
|||
ClientName: version.AppName,
|
||||
}
|
||||
b.password = config.GetString("token")
|
||||
return b
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *SubsonicApiBackend) ExportLoves(oldestTimestamp time.Time, results chan models.LovesResult, progress chan models.Progress) {
|
||||
|
|
|
@ -27,13 +27,14 @@ import (
|
|||
"go.uploadedlobster.com/scotty/internal/config"
|
||||
)
|
||||
|
||||
func TestFromConfig(t *testing.T) {
|
||||
func TestInitConfig(t *testing.T) {
|
||||
c := viper.New()
|
||||
c.Set("server-url", "https://subsonic.example.com")
|
||||
c.Set("token", "thetoken")
|
||||
service := config.NewServiceConfig("test", c)
|
||||
backend := (&subsonic.SubsonicApiBackend{}).FromConfig(&service)
|
||||
assert.IsType(t, &subsonic.SubsonicApiBackend{}, backend)
|
||||
backend := subsonic.SubsonicApiBackend{}
|
||||
err := backend.InitConfig(&service)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestSongToLove(t *testing.T) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue