-
Notifications
You must be signed in to change notification settings - Fork 22
/
userStatistics_test.go
32 lines (29 loc) · 954 Bytes
/
userStatistics_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
// Copyright 2020 rateLimit Author(https://github.com/yudeguang/ratelimit). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/yudeguang/ratelimit.
package ratelimit
import (
"testing"
"time"
)
func Test_userStatistics(t *testing.T) {
r := NewRule()
r.AddRule(time.Hour*1, 100)
r.AddRule(time.Second*10, 2)
r.AllowVisit("ydg")
r.AllowVisit("chery")
r.AllowVisit("ydg")
r.AllowVisit("vivian")
curOnlineUsersVisitsDetail := r.GetCurOnlineUsersVisitsDetail()
//log.Println(curOnlineUsersVisitsDetail)
user := curOnlineUsersVisitsDetail[2][0]
remainingVisit := curOnlineUsersVisitsDetail[2][1]
if user != "ydg" {
t.Fatalf("unexpected value obtained; got %q want %q", user, "ydg")
}
if remainingVisit != "0" {
t.Fatalf("unexpected value obtained; got %q want %q", remainingVisit, "0")
}
}