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