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

@ -24,8 +24,8 @@ import (
"strconv"
"time"
"github.com/spf13/viper"
"go.uploadedlobster.com/scotty/internal/auth"
"go.uploadedlobster.com/scotty/internal/config"
"go.uploadedlobster.com/scotty/internal/models"
"golang.org/x/oauth2"
"golang.org/x/oauth2/spotify"
@ -51,7 +51,7 @@ func (b *SpotifyApiBackend) Options() *[]models.BackendOption {
}}
}
func (b *SpotifyApiBackend) FromConfig(config *viper.Viper) models.Backend {
func (b *SpotifyApiBackend) FromConfig(config *config.ServiceConfig) models.Backend {
b.clientId = config.GetString("client-id")
b.clientSecret = config.GetString("client-secret")
return b

View file

@ -27,13 +27,15 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uploadedlobster.com/scotty/internal/backends/spotify"
"go.uploadedlobster.com/scotty/internal/config"
)
func TestFromConfig(t *testing.T) {
config := viper.New()
config.Set("client-id", "someclientid")
config.Set("client-secret", "someclientsecret")
backend := (&spotify.SpotifyApiBackend{}).FromConfig(config)
c := viper.New()
c.Set("client-id", "someclientid")
c.Set("client-secret", "someclientsecret")
service := config.NewServiceConfig("test", c)
backend := (&spotify.SpotifyApiBackend{}).FromConfig(&service)
assert.IsType(t, &spotify.SpotifyApiBackend{}, backend)
}