proxy-pool/internal/controller/bootstrap/infrastructure_test.go
2026-07-30 11:38:33 +08:00

55 lines
1.9 KiB
Go

package bootstrap
import (
"context"
"errors"
"strings"
"testing"
"proxy-pool/internal/config"
)
func TestProductionInfrastructureRejectsInvalidStorageWithoutLeakingURLs(t *testing.T) {
t.Parallel()
postgresSecret := "postgres-secret"
_, err := (&productionInfrastructure{}).Open(context.Background(), &config.Config{
Admin: config.Listener{Enabled: true},
Storage: config.Storage{PostgresURL: "postgres://user:" + postgresSecret + "@%zz"},
})
if !errors.Is(err, ErrPostgresConfiguration) || strings.Contains(err.Error(), postgresSecret) {
t.Fatalf("Open(invalid PostgreSQL) error = %v", err)
}
redisSecret := "redis-secret"
_, err = (&productionInfrastructure{}).Open(context.Background(), &config.Config{
Distribution: config.Distribution{Listener: config.Listener{Enabled: true}},
Storage: config.Storage{RedisURL: "redis://user:" + redisSecret + "@%zz"},
})
if !errors.Is(err, ErrRedisConfiguration) || strings.Contains(err.Error(), redisSecret) {
t.Fatalf("Open(invalid Redis) error = %v", err)
}
}
func TestProductionRedisSizingUsesConfigurationBounds(t *testing.T) {
t.Parallel()
configuration := &config.Config{
Distribution: config.Distribution{Extraction: config.Extraction{
MaxCountPerRequest: 100, ReserveForGateway: 5_000,
}},
Upstreams: map[string]config.Upstream{
"provider-a": {Pool: config.Pool{MaxSize: 3_000}},
"provider-b": {Pool: config.Pool{MaxSize: 2_000}},
},
}
if got := credentialCapacity(configuration); got != 5_000 {
t.Fatalf("credentialCapacity() = %d, want 5000", got)
}
if got := candidateScan(configuration); got != 5_100 {
t.Fatalf("candidateScan() = %d, want 5100", got)
}
configuration.Distribution.Extraction = config.Extraction{MaxCountPerRequest: 1}
if got := candidateScan(configuration); got != redisMinimumScan {
t.Fatalf("candidateScan(minimum) = %d, want %d", got, redisMinimumScan)
}
}