first commit

This commit is contained in:
Yangtao
2025-11-18 17:48:20 +08:00
commit 6e56cab848
196 changed files with 65809 additions and 0 deletions

69
pkg/tools/jwt_test.go Normal file
View 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())
}