papibot/pkg/validation/validation_test.go
Javier Feliz d9be5a78c8
All checks were successful
Run Go Tests / Run Tests (pull_request) Successful in 13m35s
Add validation package
2025-02-09 00:25:41 -05:00

52 lines
953 B
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 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")
}
}