diff --git a/internal/plugin/interface.go b/internal/plugin/interface.go index a5f6246..7122273 100644 --- a/internal/plugin/interface.go +++ b/internal/plugin/interface.go @@ -45,6 +45,9 @@ func RegisterPlugin(plugin Plugin) error { func compileSourceType(source data.Source) (data.Source, error) { if source.SourceType != nil { + if _, ok := namePlugins[source.SourceType.Name]; !ok { + return source, errors.New("source type " + source.SourceType.Name + " not found") + } return source, nil } diff --git a/internal/plugin/plugin_test.go b/internal/plugin/plugin_test.go index 0c83d39..1c6b2ae 100644 --- a/internal/plugin/plugin_test.go +++ b/internal/plugin/plugin_test.go @@ -141,3 +141,30 @@ func TestFetchArtist(t *testing.T) { t.Errorf(`didn't correctly parse the name`) } } + +func TestFetchWrongUrl(t *testing.T) { + RegisterPlugin(MusifyTest{}) + + _, err := Fetch(data.Source{ + Url: "https://musify.club/", + }) + + if err == nil { + t.Errorf(`trying to fetch an unknown url should result in error`) + } +} + +func TestNonExistentSourceType(t *testing.T) { + RegisterPlugin(MusifyTest{}) + + _, err := Fetch(data.Source{ + Url: "https://musify.club/", + SourceType: &data.SourceType{ + Name: "doesn't exist", + }, + }) + + if err == nil { + t.Errorf(`trying to fetch a not recognized source type should result in error`) + } +}