Renamed Backend.FromConfig to Backend.InitConfig and added error handling

This commit is contained in:
Philipp Wolfer 2025-04-29 10:03:28 +02:00
parent aad542850a
commit 0f4b04c641
No known key found for this signature in database
GPG key ID: 8FDF744D4919943B
21 changed files with 60 additions and 48 deletions

View file

@ -51,13 +51,13 @@ func (b *MalojaApiBackend) Options() []models.BackendOption {
}}
}
func (b *MalojaApiBackend) FromConfig(config *config.ServiceConfig) models.Backend {
func (b *MalojaApiBackend) InitConfig(config *config.ServiceConfig) error {
b.client = NewClient(
config.GetString("server-url"),
config.GetString("token"),
)
b.nofix = config.GetBool("nofix", false)
return b
return nil
}
func (b *MalojaApiBackend) StartImport() error { return nil }

View file

@ -26,12 +26,13 @@ import (
"go.uploadedlobster.com/scotty/internal/config"
)
func TestFromConfig(t *testing.T) {
func TestInitConfig(t *testing.T) {
c := viper.New()
c.Set("token", "thetoken")
service := config.NewServiceConfig("test", c)
backend := (&maloja.MalojaApiBackend{}).FromConfig(&service)
assert.IsType(t, &maloja.MalojaApiBackend{}, backend)
backend := maloja.MalojaApiBackend{}
err := backend.InitConfig(&service)
assert.NoError(t, err)
}
func TestScrobbleAsListen(t *testing.T) {