-
Notifications
You must be signed in to change notification settings - Fork 0
/
task_test.go
43 lines (40 loc) · 1.05 KB
/
task_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
package main
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestCheckExpiration(t *testing.T) {
now,
_, _,
validToken1, validToken2,
_, _, _, _ := setupTestToken()
for _, data := range []struct {
offset int
valid1 bool
valid2 bool
}{
{offset: 5, valid1: true, valid2: true},
{offset: 6, valid1: false, valid2: true},
{offset: 7, valid1: false, valid2: true},
{offset: 8, valid1: false, valid2: false},
{offset: 9, valid1: false, valid2: false},
} {
config.authDuration = 5 * time.Second
config.authTimeout = 5 * time.Second
state.authCache = map[string]time.Time{}
useToken(validToken1, now.Add(1*time.Second))
useToken(validToken2, now.Add(3*time.Second))
checkExpiration(now.Add(time.Duration(data.offset) * time.Second))
if data.valid1 {
assert.Contains(t, state.authCache, validToken1)
} else {
assert.NotContains(t, state.authCache, validToken1)
}
if data.valid2 {
assert.Contains(t, state.authCache, validToken2)
} else {
assert.NotContains(t, state.authCache, validToken2)
}
}
}