mirror of
https://git.sr.ht/~phw/scotty
synced 2025-04-30 05:37:05 +02:00
Use config.ServiceConfig across API
This commit is contained in:
parent
091b3c2f49
commit
9c363cc06d
27 changed files with 137 additions and 99 deletions
|
@ -21,7 +21,7 @@ import (
|
|||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
"go.uploadedlobster.com/scotty/internal/config"
|
||||
"go.uploadedlobster.com/scotty/internal/models"
|
||||
"go.uploadedlobster.com/scotty/pkg/jspf"
|
||||
)
|
||||
|
@ -56,7 +56,7 @@ func (b *JSPFBackend) Options() *[]models.BackendOption {
|
|||
}}
|
||||
}
|
||||
|
||||
func (b *JSPFBackend) FromConfig(config *viper.Viper) models.Backend {
|
||||
func (b *JSPFBackend) FromConfig(config *config.ServiceConfig) models.Backend {
|
||||
b.filePath = config.GetString("file-path")
|
||||
b.title = config.GetString("title")
|
||||
b.creator = config.GetString("username")
|
||||
|
|
|
@ -22,15 +22,17 @@ import (
|
|||
|
||||
"github.com/spf13/viper"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"go.uploadedlobster.com/scotty/internal/backends/scrobblerlog"
|
||||
"go.uploadedlobster.com/scotty/internal/backends/jspf"
|
||||
"go.uploadedlobster.com/scotty/internal/config"
|
||||
)
|
||||
|
||||
func TestFromConfig(t *testing.T) {
|
||||
config := viper.New()
|
||||
config.Set("file-path", "/foo/bar.jspf")
|
||||
config.Set("title", "My Playlist")
|
||||
config.Set("username", "outsidecontext")
|
||||
config.Set("identifier", "http://example.com/playlist1")
|
||||
backend := (&scrobblerlog.ScrobblerLogBackend{}).FromConfig(config)
|
||||
assert.IsType(t, &scrobblerlog.ScrobblerLogBackend{}, backend)
|
||||
c := viper.New()
|
||||
c.Set("file-path", "/foo/bar.jspf")
|
||||
c.Set("title", "My Playlist")
|
||||
c.Set("username", "outsidecontext")
|
||||
c.Set("identifier", "http://example.com/playlist1")
|
||||
service := config.NewServiceConfig("test", c)
|
||||
backend := (&jspf.JSPFBackend{}).FromConfig(&service)
|
||||
assert.IsType(t, &jspf.JSPFBackend{}, backend)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue