standardise all validate tests

This commit is contained in:
Aneurin Barker Snook
2023-10-08 15:21:02 +01:00
parent c74486d122
commit 7cb1900ec1
6 changed files with 65 additions and 113 deletions
+7 -10
View File
@@ -5,24 +5,21 @@ import "testing"
func TestEmail(t *testing.T) {
type TestCase struct {
Input string
Err bool
Err error
}
testCases := []TestCase{
{Input: "test@example.com"},
{Input: "testexample.com", Err: true},
{Input: "testexample.com", Err: ErrInvalidEmail},
}
for _, tc := range testCases {
t.Logf("Testing %q", tc.Input)
err := Email(tc.Input)
if tc.Err {
if err == nil {
t.Errorf("Expected %q to be an invalid email; got nil", tc.Input)
}
} else {
if err != nil {
t.Errorf("Expected %q to be a valid email; got %s", tc.Input, err)
}
if err != tc.Err {
t.Errorf("Expected error %v, got %v", tc.Err, err)
}
}
}