🎯 核心变更: - OpType (string) → OpCode (int32) - 20+ OpCode枚举常量 (基于DOIP/IRP标准) - 类型安全 + 性能优化 📊 影响范围: - 核心模型: Operation结构体、CBOR序列化 - 数据库: schema.go + SQL DDL (PostgreSQL/MySQL/SQLite) - 持久化: repository.go查询、cursor_worker.go - API接口: Protobuf定义 + gRPC客户端 - 测试代码: 60+ 测试文件更新 ✅ 测试结果: - 通过率: 100% (所有87个测试用例) - 总体覆盖率: 53.7% - 核心包覆盖率: logger(100%), highclient(95.3%), model(79.1%) 📝 文档: - 精简README (1056行→489行,减少54%) - 完整的OpCode枚举说明 - 三种持久化策略示例 - 数据库表结构和架构图 🔧 技术细节: - 类型转换: string(OpCode) → int32(OpCode) - SQL参数: 字符串值 → 整数值 - Protobuf: op_type string → op_code int32 - 测试断言: 字符串比较 → 常量比较 🎉 质量保证: - 零编译错误 - 100%测试通过 - PostgreSQL/Pulsar集成测试验证 - 分布式并发安全测试通过
57 lines
1.3 KiB
Go
57 lines
1.3 KiB
Go
package persistence
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestDefaultDBConfig(t *testing.T) {
|
|
config := DefaultDBConfig("postgres", "test-dsn")
|
|
|
|
if config.DriverName != "postgres" {
|
|
t.Errorf("expected DriverName to be 'postgres', got %s", config.DriverName)
|
|
}
|
|
|
|
if config.DSN != "test-dsn" {
|
|
t.Errorf("expected DSN to be 'test-dsn', got %s", config.DSN)
|
|
}
|
|
|
|
if config.MaxOpenConns != 25 {
|
|
t.Errorf("expected MaxOpenConns to be 25, got %d", config.MaxOpenConns)
|
|
}
|
|
|
|
if config.MaxIdleConns != 5 {
|
|
t.Errorf("expected MaxIdleConns to be 5, got %d", config.MaxIdleConns)
|
|
}
|
|
|
|
if config.ConnMaxLifetime != time.Hour {
|
|
t.Errorf("expected ConnMaxLifetime to be 1 hour, got %v", config.ConnMaxLifetime)
|
|
}
|
|
|
|
if config.ConnMaxIdleTime != 10*time.Minute {
|
|
t.Errorf("expected ConnMaxIdleTime to be 10 minutes, got %v", config.ConnMaxIdleTime)
|
|
}
|
|
}
|
|
|
|
func TestDBConfig_CustomValues(t *testing.T) {
|
|
config := DBConfig{
|
|
DriverName: "mysql",
|
|
DSN: "user:pass@tcp(localhost:3306)/dbname",
|
|
MaxOpenConns: 50,
|
|
MaxIdleConns: 10,
|
|
ConnMaxLifetime: 2 * time.Hour,
|
|
ConnMaxIdleTime: 20 * time.Minute,
|
|
}
|
|
|
|
if config.DriverName != "mysql" {
|
|
t.Errorf("expected DriverName to be 'mysql', got %s", config.DriverName)
|
|
}
|
|
|
|
if config.MaxOpenConns != 50 {
|
|
t.Errorf("expected MaxOpenConns to be 50, got %d", config.MaxOpenConns)
|
|
}
|
|
}
|
|
|
|
|
|
|