Skip to content

Commit

Permalink
feature ✨增加对MapClaims的测试
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanghaibo committed Oct 25, 2022
1 parent 3d2b677 commit 0fdfe4b
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions sdk/pkg/jwtauth/user/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,23 @@ import (
)

func TestGetUserId(t *testing.T) {
mapClaims := make(jwt.MapClaims)
var text = `{"identity":2147483647}`
err := json.Unmarshal([]byte(text), &mapClaims)
if err != nil {
t.Error(err)
}

c := &gin.Context{}

c.Set(jwt.JwtPayloadKey, mapClaims)
userId := GetUserId(c)
if userId != 2147483647 {
t.Errorf("got %v, want %v", userId, 2147483647)
}
}

func TestGetUserIdInt64(t *testing.T) {
mapClaims := make(jwt.MapClaims)
var text = `{"identity":9223372036854775807}`
err := json.Unmarshal([]byte(text), &mapClaims)
Expand Down

0 comments on commit 0fdfe4b

Please sign in to comment.