-
Notifications
You must be signed in to change notification settings - Fork 0
/
is_int_validator_test.go
57 lines (48 loc) · 1.58 KB
/
is_int_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
package validators
import (
"testing"
)
func TestIsInt(t *testing.T) {
/// - Successes
// Test 1
err, abortValidation = IsInt()(1)
if err != nil || abortValidation {
t.Errorf(setError("IsInt()(1) = %v, %t; expected: nil, false"))
}
// Test 2
err, abortValidation = IsInt(errCustomMessage)(1)
if err != nil || abortValidation {
t.Errorf(setError("IsInt(\"error\")(1) = %v, %t; expected: nil, false"))
}
/// - Errors
// Test 1
err, abortValidation = IsInt()(nil)
if err == nil || !abortValidation {
t.Errorf(setError("IsInt()(nil) = %v, %t; expected: \"[error message]\", true"))
}
// Test 2
err, abortValidation = IsInt(errCustomMessage)(nil)
if err == nil || err.Error() != errCustom.Error() || !abortValidation {
t.Errorf(setError("IsInt(\"error\")(nil) = %v, %t; expected: \"error\", true"))
}
// Test 3
err, abortValidation = IsInt()("")
if err == nil || !abortValidation {
t.Errorf(setError("IsInt()(\"\") = %v, %t; expected: \"[error message]\", true"))
}
// Test 4
err, abortValidation = IsInt(errCustomMessage)("")
if err == nil || err.Error() != errCustom.Error() || !abortValidation {
t.Errorf(setError("IsInt(\"error\")(\"\") = %v, %t; expected: \"error\", true"))
}
// Test 5
err, abortValidation = IsInt()(1.1)
if err == nil || !abortValidation {
t.Errorf(setError("IsInt()(1.1) = %v, %t; expected: \"[error message]\", true"))
}
// Test 6
err, abortValidation = IsInt(errCustomMessage)(1.1)
if err == nil || err.Error() != errCustom.Error() || !abortValidation {
t.Errorf(setError("IsInt(\"error\")(1.1) = %v, %t; expected: \"error\", true"))
}
}