-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathtimestamp_test.go
53 lines (41 loc) · 1.25 KB
/
timestamp_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
package checker
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
type timestamp struct {
Date string
StartDate *time.Time
StartDateStr string
RangeDate time.Time
RangeDateStr string
}
func TestRuleTimeStampStr(t *testing.T) {
layout := "2006-01-02"
startDate, _ := time.Parse(layout, "2020-12-12")
endDate, _ := time.Parse(layout, "2020-12-31")
rangeDate, _ := time.Parse(layout, "2020-12-20")
tsChecker := NewChecker()
tsRule := Time("Date", layout)
tsChecker.Add(tsRule, "invalid Date")
tsEqRule := EqTime("StartDate", startDate)
tsChecker.Add(tsEqRule, "invalid StartDate")
tsStrRule := EqTimeStr("StartDateStr", layout, startDate)
tsChecker.Add(tsStrRule, "invalid StartDateStr")
rangeTsRule := RangeTime("RangeDate", startDate, endDate)
tsChecker.Add(rangeTsRule, "invalid RangeDate")
rangeTsStrRule := RangeTimeStr("RangeDateStr",
layout, startDate, endDate)
tsChecker.Add(rangeTsStrRule, "invalid RangeDateStr")
startDateTs, _ := time.Parse(layout, "2020-12-12")
ts := timestamp{
Date: "2020-12-01",
StartDate: &startDateTs,
StartDateStr: "2020-12-12",
RangeDate: rangeDate,
RangeDateStr: "2020-12-15",
}
isValid, _, _ := tsChecker.Check(ts)
assert.Equal(t, true, isValid)
}