-
Notifications
You must be signed in to change notification settings - Fork 2
/
jwt_test.go
36 lines (29 loc) · 887 Bytes
/
jwt_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
package utils
import (
"github.com/dgrijalva/jwt-go"
"testing"
)
var secret = []byte("123456")
func TestGetJwtToken(t *testing.T) {
t.Log(GetJwtToken(jwt.MapClaims{"uid": "123456"}, secret))
}
func BenchmarkGetJwtToken(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
if _, err := GetJwtToken(jwt.MapClaims{"uid": "1111111"}, secret); err != nil {
b.Error(err)
}
}
}
func TestCheckJwtToken(t *testing.T) {
claims, err := CheckJwtToken("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOiIxMjM0NTYifQ.Dk0VoNVjTYygBjWwVw1TTRsDyH6vWbPUfuxSySgnzFk", secret)
t.Log(err, claims,claims["uid"])
}
func BenchmarkCheckJwtToken(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
if _, err := CheckJwtToken("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOiIxMjM0NTYifQ.Dk0VoNVjTYygBjWwVw1TTRsDyH6vWbPUfuxSySgnzFk", secret);err!=nil{
b.Error(err)
}
}
}