trepa/internal/core/jwt_test.go
qpismont 9d544c7e8a
All checks were successful
ci/woodpecker/push/lint Pipeline was successful
ci/woodpecker/push/tests Pipeline was successful
ci/woodpecker/push/build Pipeline was successful
Update CI configuration to use Go 1.24.1-alpine for build, lint, and test steps. Fix test database setup path in account tests and improve error handling in JWT verification.
2025-03-24 20:55:54 +00:00

29 lines
490 B
Go

package core
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestJWT_GenerateToken(t *testing.T) {
InitJWT("secret")
token, err := SignJWT(JWTClaims{
AccountId: 1,
RoleId: 1,
})
if err != nil {
t.Fatalf("Failed to generate token: %v", err)
}
assert.NotEmpty(t, token)
claims, jwtErr := VerifyJWT(token)
if jwtErr != nil {
t.Fatalf("Failed to verify token: %v", jwtErr)
}
assert.Equal(t, claims.AccountId, 1)
assert.Equal(t, claims.RoleId, 1)
}