mirror of
https://git.sr.ht/~phw/scotty
synced 2025-07-01 15:51:56 +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
|
@ -60,7 +60,7 @@ func (b *JSPFBackend) Options() []models.BackendOption {
|
|||
}}
|
||||
}
|
||||
|
||||
func (b *JSPFBackend) FromConfig(config *config.ServiceConfig) models.Backend {
|
||||
func (b *JSPFBackend) InitConfig(config *config.ServiceConfig) error {
|
||||
b.filePath = config.GetString("file-path")
|
||||
b.append = config.GetBool("append", true)
|
||||
b.playlist = jspf.Playlist{
|
||||
|
@ -75,7 +75,7 @@ func (b *JSPFBackend) FromConfig(config *config.ServiceConfig) models.Backend {
|
|||
},
|
||||
},
|
||||
}
|
||||
return b
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *JSPFBackend) StartImport() error {
|
||||
|
|
|
@ -26,13 +26,14 @@ import (
|
|||
"go.uploadedlobster.com/scotty/internal/config"
|
||||
)
|
||||
|
||||
func TestFromConfig(t *testing.T) {
|
||||
func TestInitConfig(t *testing.T) {
|
||||
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)
|
||||
backend := jspf.JSPFBackend{}
|
||||
err := backend.InitConfig(&service)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue