papibot/pkg/validation/validation_test.go
Javier Feliz 69f8a58f37
Some checks failed
Run Go Tests / Run Tests (pull_request) Has been cancelled
Remove log
2025-02-13 23:57:03 -05:00

85 lines
1.5 KiB
Go

package validation
import (
"testing"
)
func TestIsUrl(t *testing.T) {
is, _ := IsUrl("definitely not a url")
if is {
t.Error("Non-url text detected as URL")
}
is, _ = IsUrl("https://example.com")
if !is {
t.Error("URL not detected as URL")
}
}
func TestSchemeHandling(t *testing.T) {
// No scheme but valid url
is, _ := IsUrl("youtube.com")
if !is {
t.Error("URL without scheme came back as not a url")
}
// Preserve scheme
is, parsed := IsUrl("ftp://youtube.com")
if !is {
t.Error("URL without scheme came back as not a url")
}
if parsed.Scheme != "ftp" {
t.Error("URL scheme was replaced incorrectly")
}
}
func TestSupportedMusicUrls(t *testing.T) {
// Test actual music url
for _, url := range musicHosts {
is, _ := IsMusicUrl(url)
if !is {
t.Error("Supported service was detected as unsupported")
}
}
}
func TestIsMusicUrlErrors(t *testing.T) {
// Not a URL
is, err := IsMusicUrl("not a url")
if is {
t.Error("Non-URL was detected as url")
}
if err != ErrNotAUrl {
t.Error("Incorrect error returned for Non-url link")
}
// Incorrect protocol
is, err = IsMusicUrl("ssh://youtube.com")
if is {
t.Error("Incorrect protocol was not caught")
}
if err != ErrIncorrectProtocol {
t.Error("Incorrect error returned for incorrect protocol")
}
// Unsupported service
is, err = IsMusicUrl("https://www.deezer.com/")
if is {
t.Error("Unsupported service was not caught")
}
if err != ErrServiceUnsupported {
t.Error("Unsupported service did not return the correct error")
}
}