allowing pointer

This commit is contained in:
Hazel Noack 2025-10-08 10:32:43 +02:00
parent 8587bdf360
commit a99dee5104
4 changed files with 24 additions and 12 deletions

View File

@ -23,7 +23,7 @@ func printResults(musicObjects []data.MusicObject) {
}
func Shell() {
plugin.RegisterPlugin(plugin.Musify{})
plugin.RegisterPlugin(&plugin.Musify{})
for {
fmt.Print("> ")

View File

@ -15,6 +15,8 @@ type Plugin interface {
RegexAlbum() *regexp.Regexp
RegexSong() *regexp.Regexp
Init()
Search(query common.Query) ([]data.MusicObject, error)
FetchArtist(source data.Source) (data.Artist, error)

View File

@ -35,10 +35,20 @@ func (m Musify) RegexAlbum() *regexp.Regexp {
return regexp.MustCompile(`(?i)https?://musify\.club/release/[a-z\-0-9]+`)
}
func (m *Musify) Init() {
}
func (m Musify) RegexSong() *regexp.Regexp {
return regexp.MustCompile(`(?i)https?://musify\.club/track/[a-z\-0-9]+`)
}
func (m Musify) Search(query common.Query) ([]data.MusicObject, error) {
res := []data.MusicObject{}
return res, nil
}
func (m Musify) FetchSong(source data.Source) (data.Song, error) {
return data.Song{
Name: extractName(source.Url),
@ -56,7 +66,3 @@ func (m Musify) FetchArtist(source data.Source) (data.Artist, error) {
Name: extractName(source.Url),
}, nil
}
func (m Musify) Search(query common.Query) ([]data.MusicObject, error) {
return []data.MusicObject{}, nil
}

View File

@ -40,6 +40,10 @@ func (m MusifyTest) RegexSong() *regexp.Regexp {
return regexp.MustCompile(`(?i)https?://musify\.club/track/[a-z\-0-9]+`)
}
func (m *MusifyTest) Init() {
}
func (m MusifyTest) FetchSong(source data.Source) (data.Song, error) {
return data.Song{
Name: extractNameTest(source.Url),
@ -63,11 +67,11 @@ func (m MusifyTest) Search(query common.Query) ([]data.MusicObject, error) {
}
func TestRegister(t *testing.T) {
if RegisterPlugin(MusifyTest{}) != nil {
if RegisterPlugin(&MusifyTest{}) != nil {
t.Errorf(`registering first plugin shouldn't return an error`)
}
if RegisterPlugin(MusifyTest{}) == nil {
if RegisterPlugin(&MusifyTest{}) == nil {
t.Errorf(`registering same plugin twice should return an error`)
}
@ -81,7 +85,7 @@ func TestRegister(t *testing.T) {
}
func TestFetchSong(t *testing.T) {
RegisterPlugin(MusifyTest{})
RegisterPlugin(&MusifyTest{})
s, err := Fetch(data.Source{
Url: "https://musify.club/track/linkin-park-in-the-end-3058",
@ -102,7 +106,7 @@ func TestFetchSong(t *testing.T) {
}
func TestFetchAlbum(t *testing.T) {
RegisterPlugin(MusifyTest{})
RegisterPlugin(&MusifyTest{})
a, err := Fetch(data.Source{
Url: "https://musify.club/release/linkin-park-hybrid-theory-2000-188",
@ -123,7 +127,7 @@ func TestFetchAlbum(t *testing.T) {
}
func TestFetchArtist(t *testing.T) {
RegisterPlugin(MusifyTest{})
RegisterPlugin(&MusifyTest{})
a, err := Fetch(data.Source{
Url: "https://musify.club/artist/linkin-park-5",
@ -144,7 +148,7 @@ func TestFetchArtist(t *testing.T) {
}
func TestFetchWrongUrl(t *testing.T) {
RegisterPlugin(MusifyTest{})
RegisterPlugin(&MusifyTest{})
_, err := Fetch(data.Source{
Url: "https://musify.club/",
@ -156,7 +160,7 @@ func TestFetchWrongUrl(t *testing.T) {
}
func TestNonExistentSourceType(t *testing.T) {
RegisterPlugin(MusifyTest{})
RegisterPlugin(&MusifyTest{})
_, err := Fetch(data.Source{
Url: "https://musify.club/",