-
Notifications
You must be signed in to change notification settings - Fork 0
/
max_length_validator_test.go
87 lines (74 loc) · 2.83 KB
/
max_length_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
76
77
78
79
80
81
82
83
84
85
86
87
package validators
import (
"testing"
)
func TestMaxLength(t *testing.T) {
/// - Successes
/// String size
// Test 1
err, abortValidation = MaxLength(5)("aA")
if err != nil || abortValidation {
t.Errorf(setError("MaxLength(5)(\"aA\") = %v, %t; expected: nil, false"))
}
/// Slice Size
// Test 2
err, abortValidation = MaxLength(5)([]int{0, 1, 2, 3, 4})
if err != nil || abortValidation {
t.Errorf(setError("MaxLength(5)([]int{0, 1, 2, 3, 4}) = %v, %t; expected: nil, false"))
}
/// Array size
// Test 3
err, abortValidation = MaxLength(5)([5]int{0, 1, 2, 3, 4})
if err != nil || abortValidation {
t.Errorf(setError("MaxLength(5)([5]int{0, 1, 2, 3, 4}) = %v, %t; expected: nil, false"))
}
// Test 4
err, abortValidation = MaxLength(5)([5]int{0, 1, 2, 3})
if err != nil || abortValidation {
t.Errorf(setError("MaxLength(5)([5]int{0, 1, 2, 3}) = %v, %t; expected: nil, false"))
}
/// - Errors
/// String size
// Test 1
err, abortValidation = MaxLength(5)("aAbBcC")
if err == nil || abortValidation {
t.Errorf(setError("MaxLength(5)(\"aAbBcC\") = %v, %t; expected: \"[error message]\", false"))
}
// Test 2
err, abortValidation = MaxLength(5, errCustomMessage)("aAbBcC")
if err == nil || err.Error() != errCustom.Error() || abortValidation {
t.Errorf(setError("MaxLength(5, \"error\")(\"aAbBcC\") = %v, %t; expected: \"error\", false"))
}
/// Slice Size
// Test 3
err, abortValidation = MaxLength(5)([]int{0, 1, 2, 3, 4, 5})
if err == nil || abortValidation {
t.Errorf(setError("MaxLength(5)([]int{0, 1, 2, 3, 4, 5}) = %v, %t; expected: \"[error message]\", false"))
}
// Test 4
err, abortValidation = MaxLength(5, errCustomMessage)([]int{0, 1, 2, 3, 4, 5})
if err == nil || err.Error() != errCustom.Error() || abortValidation {
t.Errorf(setError("MaxLength(5, \"error\")([]int{0, 1, 2, 3, 4, 5}) = %v, %t; expected: \"error\", false"))
}
/// Array Size
// Test 5
err, abortValidation = MaxLength(5)([6]int{0, 1, 2, 3, 4, 5})
if err == nil || abortValidation {
t.Errorf(setError("MaxLength(5)([6]int{0, 1, 2, 3, 4, 5}) = %v, %t; expected: \"[error message]\", false"))
}
// Test 6
err, abortValidation = MaxLength(5, errCustomMessage)([6]int{0, 1, 2, 3, 4, 5})
if err == nil || err.Error() != errCustom.Error() || abortValidation {
t.Errorf(setError("MaxLength(5, \"error\")([6]int{0, 1, 2, 3, 4, 5}) = %v, %t; expected: \"error\", false"))
}
// Test 7
err, abortValidation = MaxLength(5)([6]int{0, 1, 2, 3})
if err == nil || abortValidation {
t.Errorf(setError("MaxLength(5)([6]int{0, 1, 2, 3}) = %v, %t; expected: \"[error message]\", false"))
}
// Test 8
err, abortValidation = MaxLength(5, errCustomMessage)([6]int{0, 1, 2, 3})
if err == nil || err.Error() != errCustom.Error() || abortValidation {
t.Errorf(setError("MaxLength(5, \"error\")([6]int{0, 1, 2, 3}) = %v, %t; expected: \"error\", false"))
}
}