-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtoken_test.go
48 lines (40 loc) · 966 Bytes
/
token_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
package mnemosyne_test
import (
"context"
"testing"
"github.com/piotrkowalczuk/mnemosyne"
)
func TestNewAccessTokenContext(t *testing.T) {
exp := "123"
ctx := mnemosyne.NewAccessTokenContext(context.Background(), exp)
if got, ok := mnemosyne.AccessTokenFromContext(ctx); ok {
if exp != got {
t.Errorf("wrong access token, expected %s but got %s", exp, got)
}
return
}
t.Error("missing access token")
}
func TestRandomToken(t *testing.T) {
token, err := mnemosyne.RandomAccessToken()
if err != nil {
t.Fatalf("unexpected error: %s", err.Error())
}
if len(token) != 128 {
t.Errorf("wrong length, expected %d but got %d", 128, len(token))
}
}
var (
benchAccessToken string
)
func BenchmarkRandomAccessToken(b *testing.B) {
bn := int32(b.N)
b.ResetTimer()
for n := int32(1); n < bn; n++ {
at, err := mnemosyne.RandomAccessToken()
if err != nil {
b.Fatalf("unexpected error: %s", err.Error())
}
benchAccessToken = at
}
}