Files
validate/email_test.go
T

47 lines
797 B
Go
Raw Normal View History

2023-10-06 11:58:24 +01:00
package validate
import (
"errors"
2024-07-18 06:53:20 +01:00
"fmt"
"testing"
)
2023-10-06 11:58:24 +01:00
2024-07-18 06:53:20 +01:00
func ExampleEmail() {
fmt.Println(Email("not an email"))
// Output: invalid email address
}
func FuzzEmail(f *testing.F) {
want := ErrInvalidEmail
f.Fuzz(func(t *testing.T, input string) {
got := Email(input)
if !errors.Is(got, want) {
t.Error("got", got)
t.Error("want", want)
}
})
}
func TestEmail(t *testing.T) {
2024-07-18 06:53:20 +01:00
testCases := map[string]error{
"test@example.com": nil,
"firstname.lastname@some-website.co.uk": nil,
2023-10-06 11:58:24 +01:00
2024-07-18 06:53:20 +01:00
"not an email": ErrInvalidEmail,
"testexample.com": ErrInvalidEmail,
2023-10-06 11:58:24 +01:00
}
2024-07-18 06:53:20 +01:00
for input, want := range testCases {
t.Run(input, func(t *testing.T) {
got := Email(input)
2023-10-08 15:21:02 +01:00
2024-07-18 06:53:20 +01:00
if !errors.Is(got, want) {
t.Error("got", got)
t.Error("want", want)
}
})
2023-10-06 11:58:24 +01:00
}
}