feat: backend core - auth, user, role, permission, device, webhook, monitoring, cache, repository, service, middleware, API handlers
2026-04-02 11:19:50 +08:00
|
|
|
package repository
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"testing"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
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)
2026-04-17 20:43:50 +08:00
|
|
|
"github.com/user-management-system/internal/config"
|
feat: backend core - auth, user, role, permission, device, webhook, monitoring, cache, repository, service, middleware, API handlers
2026-04-02 11:19:50 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestBuildRedisOptions(t *testing.T) {
|
|
|
|
|
cfg := &config.Config{
|
|
|
|
|
Redis: config.RedisConfig{
|
|
|
|
|
Host: "localhost",
|
|
|
|
|
Port: 6379,
|
|
|
|
|
Password: "secret",
|
|
|
|
|
DB: 2,
|
|
|
|
|
DialTimeoutSeconds: 5,
|
|
|
|
|
ReadTimeoutSeconds: 3,
|
|
|
|
|
WriteTimeoutSeconds: 4,
|
|
|
|
|
PoolSize: 100,
|
|
|
|
|
MinIdleConns: 10,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
opts := buildRedisOptions(cfg)
|
|
|
|
|
require.Equal(t, "localhost:6379", opts.Addr)
|
|
|
|
|
require.Equal(t, "secret", opts.Password)
|
|
|
|
|
require.Equal(t, 2, opts.DB)
|
|
|
|
|
require.Equal(t, 5*time.Second, opts.DialTimeout)
|
|
|
|
|
require.Equal(t, 3*time.Second, opts.ReadTimeout)
|
|
|
|
|
require.Equal(t, 4*time.Second, opts.WriteTimeout)
|
|
|
|
|
require.Equal(t, 100, opts.PoolSize)
|
|
|
|
|
require.Equal(t, 10, opts.MinIdleConns)
|
|
|
|
|
require.Nil(t, opts.TLSConfig)
|
|
|
|
|
|
|
|
|
|
// Test case with TLS enabled
|
|
|
|
|
cfgTLS := &config.Config{
|
|
|
|
|
Redis: config.RedisConfig{
|
|
|
|
|
Host: "localhost",
|
|
|
|
|
EnableTLS: true,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
optsTLS := buildRedisOptions(cfgTLS)
|
|
|
|
|
require.NotNil(t, optsTLS.TLSConfig)
|
|
|
|
|
require.Equal(t, "localhost", optsTLS.TLSConfig.ServerName)
|
|
|
|
|
}
|