v1.1
This commit is contained in:
@@ -11,8 +11,8 @@ import (
|
||||
func TestGenerateJwtToken(t *testing.T) {
|
||||
// 测试数据
|
||||
testClaims := JwtClaims{
|
||||
UserId: 1,
|
||||
AgentId: 0,
|
||||
UserId: "1",
|
||||
AgentId: "",
|
||||
Platform: "wxh5",
|
||||
UserType: 0,
|
||||
IsAgent: 0,
|
||||
@@ -37,8 +37,8 @@ func TestGenerateJwtToken(t *testing.T) {
|
||||
{
|
||||
name: "不同用户数据",
|
||||
claims: JwtClaims{
|
||||
UserId: 99999,
|
||||
AgentId: 11111,
|
||||
UserId: "99999",
|
||||
AgentId: "",
|
||||
Platform: "mobile",
|
||||
UserType: 0,
|
||||
IsAgent: 1,
|
||||
@@ -103,8 +103,8 @@ func TestGenerateJwtToken(t *testing.T) {
|
||||
if claims, ok := parsedToken.Claims.(jwt.MapClaims); ok {
|
||||
// 验证userId
|
||||
if userId, exists := claims["userId"]; exists {
|
||||
if int64(userId.(float64)) != tt.claims.UserId {
|
||||
t.Errorf("token中的userId不匹配,期望%d,实际%v", tt.claims.UserId, userId)
|
||||
if userId.(string) != tt.claims.UserId {
|
||||
t.Errorf("token中的userId不匹配,期望%s,实际%v", tt.claims.UserId, userId)
|
||||
}
|
||||
} else {
|
||||
t.Error("token中缺少userId字段")
|
||||
@@ -144,8 +144,8 @@ func TestGenerateJwtToken(t *testing.T) {
|
||||
func TestGenerateJwtTokenAndParse(t *testing.T) {
|
||||
// 测试生成token后能够正确解析
|
||||
testClaims := JwtClaims{
|
||||
UserId: 12345,
|
||||
AgentId: 67890,
|
||||
UserId: "12345",
|
||||
AgentId: "",
|
||||
Platform: "web",
|
||||
UserType: 1,
|
||||
IsAgent: 0,
|
||||
@@ -188,8 +188,8 @@ func TestGenerateJwtTokenAndParse(t *testing.T) {
|
||||
func BenchmarkGenerateJwtToken(t *testing.B) {
|
||||
// 性能测试
|
||||
testClaims := JwtClaims{
|
||||
UserId: 12345,
|
||||
AgentId: 67890,
|
||||
UserId: "12345",
|
||||
AgentId: "",
|
||||
Platform: "web",
|
||||
UserType: 1,
|
||||
IsAgent: 0,
|
||||
@@ -209,8 +209,8 @@ func BenchmarkGenerateJwtToken(t *testing.B) {
|
||||
func TestParseJwtToken(t *testing.T) {
|
||||
// 使用你修改的测试数据
|
||||
testClaims := JwtClaims{
|
||||
UserId: 6,
|
||||
AgentId: 0,
|
||||
UserId: "6",
|
||||
AgentId: "",
|
||||
Platform: "wxh5",
|
||||
UserType: 0,
|
||||
IsAgent: 0,
|
||||
@@ -347,8 +347,8 @@ func TestParseCustomJwtToken(t *testing.T) {
|
||||
func TestGenerateAndParseWithRealData(t *testing.T) {
|
||||
// 使用真实数据生成token
|
||||
realClaims := JwtClaims{
|
||||
UserId: 1,
|
||||
AgentId: 0,
|
||||
UserId: "1",
|
||||
AgentId: "",
|
||||
Platform: "wxh5",
|
||||
UserType: 0,
|
||||
IsAgent: 0,
|
||||
|
||||
Reference in New Issue
Block a user