first commit
This commit is contained in:
69
pkg/tools/jwt_test.go
Normal file
69
pkg/tools/jwt_test.go
Normal file
@ -0,0 +1,69 @@
|
||||
package tools
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestGenerateToken(t *testing.T) {
|
||||
type args struct {
|
||||
client string
|
||||
uid string
|
||||
username string
|
||||
nickname string
|
||||
exp time.Time
|
||||
nbf time.Time
|
||||
iat time.Time
|
||||
aud []string
|
||||
}
|
||||
var now = time.Now()
|
||||
var loginExpiration = 60 * 24 * 30 // 30天
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
wantTokenStr string
|
||||
wantErr bool
|
||||
}{
|
||||
// 28a08f58496f11eeb95f0242ac110004
|
||||
{
|
||||
name: "test01",
|
||||
args: struct {
|
||||
client string
|
||||
uid string
|
||||
username string
|
||||
nickname string
|
||||
exp time.Time
|
||||
nbf time.Time
|
||||
iat time.Time
|
||||
aud []string
|
||||
}{
|
||||
client: "APP_USER",
|
||||
uid: "28a08f58496f11eeb95f0242ac110004",
|
||||
username: "driver001",
|
||||
nickname: "driver001",
|
||||
exp: now.Add(time.Minute * time.Duration(loginExpiration)),
|
||||
nbf: now,
|
||||
iat: now,
|
||||
aud: []string{},
|
||||
},
|
||||
wantTokenStr: "",
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
gotTokenStr, err := GenerateToken(tt.args.client, tt.args.uid, tt.args.username, tt.args.nickname, tt.args.exp, tt.args.nbf, tt.args.iat, tt.args.aud)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("GenerateToken() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
if gotTokenStr != tt.wantTokenStr {
|
||||
t.Errorf("GenerateToken() = %v, want %v", gotTokenStr, tt.wantTokenStr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestUuid(t *testing.T) {
|
||||
println(Uuid())
|
||||
}
|
||||
Reference in New Issue
Block a user