-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathinfraction_test.go
52 lines (44 loc) · 1015 Bytes
/
infraction_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
package badactor
import (
"strconv"
"testing"
"time"
)
func TestNewInfraction(t *testing.T) {
rn := "rn_" + strconv.FormatInt(time.Now().UnixNano(), 10)
rm := "rm_" + strconv.FormatInt(time.Now().UnixNano(), 10)
sl := 3
eb := time.Second * 60
s := time.Second * 60
r := &Rule{
Name: rn,
Message: rm,
StrikeLimit: sl,
ExpireBase: eb,
Sentence: s,
}
inf := newInfraction(r)
if inf.strikes != 0 {
t.Errorf("Infraction.Strikes should be [%v]", 0)
}
}
func TestInfractionRebase(t *testing.T) {
rn := "rn_" + strconv.FormatInt(time.Now().UnixNano(), 10)
rm := "rm_" + strconv.FormatInt(time.Now().UnixNano(), 10)
sl := 3
eb := time.Second * 60
s := time.Second * 60
r := &Rule{
Name: rn,
Message: rm,
StrikeLimit: sl,
ExpireBase: eb,
Sentence: s,
}
inf := newInfraction(r)
ot := inf.expireBy
inf.rebase()
if !inf.expireBy.After(ot) {
t.Errorf("Infraction.ExpireBy should be new, greater value, instead [%v:%v]", inf.expireBy, ot)
}
}