feat: Oracle 驱动完整化——回调体系、版本感知、驱动抽象层与测试套件

- 新增驱动抽象层 driver_adapter(go-ora/godror 双驱动切换)
- 新增 Update/Delete/Query 回调,完善 RETURNING INTO 子句
- 修复 create.go 事务悬挂行 BUG、批量 RowsAffected、主键 WHERE 注入
- 版本感知体系:分页/自增/序列默认值/BOOLEAN/32k VARCHAR2 分级能力判定
- 11g 序列+触发器自增、ON UPDATE 触发器、默认值智能转换
- 升级 go-ora v2.8.19 → v2.9.0
- 单元测试+模块测试+集成测试共 96 个,真实 Oracle 11g 全绿
- 测试 DSN 密码移除,改为 ORACLE_DSN 环境变量注入
This commit is contained in:
2026-08-08 10:36:57 +08:00
parent 1f6c8a18a3
commit 9154afab6b
35 changed files with 4956 additions and 37 deletions
+74
View File
@@ -0,0 +1,74 @@
package driver_adapter
import "testing"
// TestRegistryRegisterAndGet 验证 Register 后 Get 能返回对应适配器
func TestRegistryRegisterAndGet(t *testing.T) {
const key DriverType = "test-registry-driver"
callCount := 0
Register(key, func() Adapter {
callCount++
return &GoOraAdapter{}
})
defer delete(registry, key)
adapter := Get(key)
if adapter == nil {
t.Fatalf("Get(%q) 返回 nil,期望返回已注册的适配器", key)
}
if _, ok := adapter.(*GoOraAdapter); !ok {
t.Fatalf("Get(%q) 返回类型 = %T,期望 *GoOraAdapter", key, adapter)
}
if callCount != 1 {
t.Errorf("factory 调用次数 = %d,期望 1", callCount)
}
// 每次 Get 都应调用 factory 返回新实例
if Get(key) == nil {
t.Error("第二次 Get 返回 nil")
}
if callCount != 2 {
t.Errorf("factory 调用次数 = %d,期望 2(每次 Get 都应调用 factory", callCount)
}
}
// TestRegistryGetUnknown 验证 Get 未注册的 DriverType 返回 nil
func TestRegistryGetUnknown(t *testing.T) {
if adapter := Get(DriverType("no-such-driver")); adapter != nil {
t.Fatalf("Get(未注册类型) 返回 %v,期望 nil", adapter)
}
}
// TestRegistryListDrivers 验证 ListDrivers 返回包含 DriverGoOra
func TestRegistryListDrivers(t *testing.T) {
drivers := ListDrivers()
if len(drivers) == 0 {
t.Fatal("ListDrivers() 返回空列表")
}
for _, d := range drivers {
if d == DriverGoOra {
return
}
}
t.Errorf("ListDrivers() = %v,应包含 DriverGoOra", drivers)
}
// TestRegistryGodrorNotCompiled 验证默认构建(无 godror build tag)下不包含 DriverGodror
func TestRegistryGodrorNotCompiled(t *testing.T) {
for _, d := range ListDrivers() {
if d == DriverGodror {
t.Errorf("ListDrivers() = %v,默认构建不应包含 DriverGodrorgodror.go 带有 //go:build godror 标签)", d)
}
}
}
// TestDriverTypeConstants 验证驱动类型常量值
func TestDriverTypeConstants(t *testing.T) {
if DriverGoOra != "go-ora" {
t.Errorf("DriverGoOra = %q,期望 %q", DriverGoOra, "go-ora")
}
if DriverGodror != "godror" {
t.Errorf("DriverGodror = %q,期望 %q", DriverGodror, "godror")
}
}