-
Notifications
You must be signed in to change notification settings - Fork 4
/
after_test.go
70 lines (62 loc) · 1.63 KB
/
after_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
package govalidator
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func Test_After(t *testing.T) {
tests := []struct {
name string
field string
value string
afterValue string
isPassed bool
msg string
expectedMsg string
}{
{
name: "test time instant 2012-01-01 is after 2009-11-02",
field: "birth_date",
value: "2012-01-01",
afterValue: "2009-11-02",
isPassed: true,
msg: "",
expectedMsg: "",
},
{
name: "test time instant 2010-01-01 isn't after 2019-01-01 and won't pass validation rule",
field: "birth_date",
value: "2010-01-01",
afterValue: "2019-01-01",
isPassed: false,
msg: "",
expectedMsg: "birth_date should be after 2019-01-01 00:00:00 +0000 UTC",
},
{
name: "test time instant 2022-01-01 isn't after 2022-02-01 and won't pass validation rule",
field: "birth_date",
value: "2022-01-01",
afterValue: "2022-02-01",
isPassed: false,
msg: "birth_date can't be before 2022-02-01.",
expectedMsg: "birth_date can't be before 2022-02-01.",
},
}
for _, test := range tests {
v := New()
value, _ := time.Parse("2006-01-02", test.value)
afterValue, _ := time.Parse("2006-01-02", test.afterValue)
v.After(value, afterValue, test.field, test.msg)
assert.Equal(t, test.isPassed, v.IsPassed(), test.name)
if !test.isPassed {
assert.Equalf(
t,
test.expectedMsg,
v.Errors()[test.field],
"test case %q failed, expected: %s, got: %s",
test.expectedMsg,
v.Errors()[test.field],
)
}
}
}