url_test.go 579 B

12345678910111213141516171819202122232425262728293031
  1. package validate
  2. import (
  3. "errors"
  4. "testing"
  5. )
  6. func TestURL(t *testing.T) {
  7. type TestCase struct {
  8. Input string
  9. Err error
  10. }
  11. testCases := []TestCase{
  12. {Input: "http://example.com"},
  13. {Input: "http://subdomain.example.com"},
  14. {Input: "http://www.example.com/some-page.html"},
  15. {Input: "subdomain.com", Err: ErrInvalidURL},
  16. {Input: "not a url", Err: ErrInvalidURL},
  17. }
  18. for n, tc := range testCases {
  19. t.Logf("(%d) Testing %q", n, tc.Input)
  20. err := URL(tc.Input)
  21. if !errors.Is(err, tc.Err) {
  22. t.Errorf("Expected error %v, got %v", tc.Err, err)
  23. }
  24. }
  25. }