Use config.ServiceConfig across API

This commit is contained in:
Philipp Wolfer 2023-12-07 23:44:58 +01:00
parent 091b3c2f49
commit 9c363cc06d
No known key found for this signature in database
GPG key ID: 8FDF744D4919943B
27 changed files with 137 additions and 99 deletions

View file

@ -22,7 +22,7 @@ import (
"sort"
"time"
"github.com/spf13/viper"
"go.uploadedlobster.com/scotty/internal/config"
"go.uploadedlobster.com/scotty/internal/models"
)
@ -52,7 +52,7 @@ func (b *ScrobblerLogBackend) Options() *[]models.BackendOption {
}}
}
func (b *ScrobblerLogBackend) FromConfig(config *viper.Viper) models.Backend {
func (b *ScrobblerLogBackend) FromConfig(config *config.ServiceConfig) models.Backend {
b.filePath = config.GetString("file-path")
b.includeSkipped = config.GetBool("include-skipped")
b.append = true

View file

@ -22,11 +22,13 @@ import (
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
"go.uploadedlobster.com/scotty/internal/backends/scrobblerlog"
"go.uploadedlobster.com/scotty/internal/config"
)
func TestFromConfig(t *testing.T) {
config := viper.New()
config.Set("token", "thetoken")
backend := (&scrobblerlog.ScrobblerLogBackend{}).FromConfig(config)
c := viper.New()
c.Set("token", "thetoken")
service := config.NewServiceConfig("test", c)
backend := (&scrobblerlog.ScrobblerLogBackend{}).FromConfig(&service)
assert.IsType(t, &scrobblerlog.ScrobblerLogBackend{}, backend)
}