-
Notifications
You must be signed in to change notification settings - Fork 152
/
rate_test.go
59 lines (50 loc) · 950 Bytes
/
rate_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
package limiter_test
import (
"reflect"
"testing"
"time"
"github.com/stretchr/testify/require"
"github.com/ulule/limiter/v3"
)
// TestRate tests Rate methods.
func TestRate(t *testing.T) {
is := require.New(t)
expected := map[string]limiter.Rate{
"10-S": {
Formatted: "10-S",
Period: 1 * time.Second,
Limit: int64(10),
},
"356-M": {
Formatted: "356-M",
Period: 1 * time.Minute,
Limit: int64(356),
},
"3-H": {
Formatted: "3-H",
Period: 1 * time.Hour,
Limit: int64(3),
},
"2000-D": {
Formatted: "2000-D",
Period: 24 * time.Hour,
Limit: int64(2000),
},
}
for k, v := range expected {
r, err := limiter.NewRateFromFormatted(k)
is.NoError(err)
is.True(reflect.DeepEqual(v, r))
}
wrongs := []string{
"10 S",
"10:S",
"AZERTY",
"na wak",
"H-10",
}
for _, w := range wrongs {
_, err := limiter.NewRateFromFormatted(w)
is.Error(err)
}
}