a9c1184d6b
also simplified structure of test cases and failure logging
35 lines
605 B
Go
35 lines
605 B
Go
package validate
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"testing"
|
|
)
|
|
|
|
func ExampleURL() {
|
|
fmt.Println(URL("not a url"))
|
|
// Output: invalid URL
|
|
}
|
|
|
|
func TestURL(t *testing.T) {
|
|
testCases := map[string]error{
|
|
"http://example.com": nil,
|
|
"http://subdomain.example.com": nil,
|
|
"http://www.example.com/some-page.html": nil,
|
|
|
|
"not a url": ErrInvalidURL,
|
|
"subdomain.com": ErrInvalidURL,
|
|
}
|
|
|
|
for input, want := range testCases {
|
|
t.Run(input, func(t *testing.T) {
|
|
got := URL(input)
|
|
|
|
if !errors.Is(got, want) {
|
|
t.Error("got", got)
|
|
t.Error("want", want)
|
|
}
|
|
})
|
|
}
|
|
}
|