-
Notifications
You must be signed in to change notification settings - Fork 0
/
email_validator_test.go
75 lines (63 loc) · 2.5 KB
/
email_validator_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package validators
import (
"testing"
)
func TestEmail(t *testing.T) {
/// - Successes
// Test 1
err, abortValidation = Email()("[email protected]")
if err != nil || abortValidation {
t.Errorf(setError("Email()(\"[email protected]\") = %v, %t; expected: nil, false"))
}
// Test 2
err, abortValidation = Email(errCustomMessage)("[email protected]")
if err != nil || abortValidation {
t.Errorf(setError("Email(\"error\")(\"[email protected]\") = %v, %t; expected: nil, false"))
}
// Test 3
err, abortValidation = Email("", errCustomMessage2)("[email protected]")
if err != nil || abortValidation {
t.Errorf(setError("Email(\"\", \"error2\")(\"[email protected]\") = %v, %t; expected: nil, false"))
}
// Test 4
err, abortValidation = Email(errCustomMessage, errCustomMessage2)("[email protected]")
if err != nil || abortValidation {
t.Errorf(setError("Email(\"error\", \"error2\")(\"[email protected]\") = %v, %t; expected: nil, false"))
}
/// - Errors
// Test 1
err, abortValidation = Email()("aA")
if err == nil || abortValidation {
t.Errorf(setError("Email()(\"aA\") = %v, %t; expected: \"[error message]\", true"))
}
// Test 2
err, abortValidation = Email(errCustomMessage)("aA")
if err == nil || err.Error() != errCustom.Error() || abortValidation {
t.Errorf(setError("Email(\"error\")(\"aA\") = %v, %t; expected: \"error\", true"))
}
// Test 3
err, abortValidation = Email()(nil)
if err == nil || abortValidation {
t.Errorf(setError("Email()(nil) = %v, %t; expected: \"[error message]\", true"))
}
// Test 4
err, abortValidation = Email("", errCustomMessage2)(nil)
if err == nil || err.Error() != errCustom2.Error() || abortValidation {
t.Errorf(setError("Email(\"\", \"error2\")(nil) = %v, %t; expected: \"error2\", true"))
}
// Test 5
err, abortValidation = Email(errCustomMessage, errCustomMessage2)(nil)
if err == nil || err.Error() != errCustom2.Error() || abortValidation {
t.Errorf(setError("Email(\"error\", \"error2\")(nil) = %v, %t; expected: \"error2\", true"))
}
// Test 6
err, abortValidation = Email()("emailexamplegmail.com")
if err == nil || abortValidation {
t.Errorf(setError("Email()(\"emailexamplegmail.com\") = %v, %t; expected: \"[error message]\", true"))
}
// Test 7
err, abortValidation = Email(errCustomMessage)("emailexamplegmail")
if err == nil || err.Error() != errCustom.Error() || abortValidation {
t.Errorf(setError("Email(\"error\")(\"emailexamplegmail.com\") = %v, %t; expected: \"error\", true"))
}
}