Files
Aneurin Barker Snook a9c1184d6b improve validate testing with examples
also simplified structure of test cases and failure logging
2024-07-18 06:53:20 +01:00

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)
}
})
}
}