test: add comprehensive test coverage and improve code quality
- Add new test files for auth, service, and handler modules - Improve test organization and coverage - Refactor code for better maintainability - Add captcha, settings, stats, and theme handler tests - Add auth module tests (CAS, OAuth, password, SSO, state) - Add service layer tests for auth, export, permissions, roles - All Go tests pass (exit code 0) - All frontend tests pass (325 tests in 59 files)
This commit is contained in:
@@ -9,10 +9,10 @@ import (
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
|
||||
_ "modernc.org/sqlite" // 纯 Go SQLite,注册 "sqlite" 驱动
|
||||
gormsqlite "gorm.io/driver/sqlite"
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/logger"
|
||||
_ "modernc.org/sqlite" // 纯 Go SQLite,注册 "sqlite" 驱动
|
||||
|
||||
"github.com/user-management-system/internal/domain"
|
||||
"github.com/user-management-system/internal/repository"
|
||||
@@ -138,12 +138,12 @@ func TestTransactionIntegration(t *testing.T) {
|
||||
|
||||
t.Run("TransactionRollback", func(t *testing.T) {
|
||||
err := db.Transaction(func(tx *gorm.DB) error {
|
||||
user := &domain.User{
|
||||
Phone: domain.StrPtr("13811111111"),
|
||||
Username: "txrollbackuser",
|
||||
Password: "hashedpassword",
|
||||
Status: domain.UserStatusActive,
|
||||
}
|
||||
user := &domain.User{
|
||||
Phone: domain.StrPtr("13811111111"),
|
||||
Username: "txrollbackuser",
|
||||
Password: "hashedpassword",
|
||||
Status: domain.UserStatusActive,
|
||||
}
|
||||
if err := tx.Create(user).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -162,12 +162,12 @@ func TestTransactionIntegration(t *testing.T) {
|
||||
|
||||
t.Run("TransactionCommit", func(t *testing.T) {
|
||||
err := db.Transaction(func(tx *gorm.DB) error {
|
||||
user := &domain.User{
|
||||
Phone: domain.StrPtr("13822222222"),
|
||||
Username: "txcommituser",
|
||||
Password: "hashedpassword",
|
||||
Status: domain.UserStatusActive,
|
||||
}
|
||||
user := &domain.User{
|
||||
Phone: domain.StrPtr("13822222222"),
|
||||
Username: "txcommituser",
|
||||
Password: "hashedpassword",
|
||||
Status: domain.UserStatusActive,
|
||||
}
|
||||
return tx.Create(user).Error
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user