mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-05-23 01:11:06 +08:00
- 标识符处理:下沉 Kingbase 引用逻辑,普通小写 schema/table 不再强制双引号包裹 - 表操作修复:修复截断、清空、导入、导出等路径生成异常双引号 SQL - 同步链路修复:统一数据同步、预览、迁移建表中的 Kingbase schema.table 拼接规则 - 自定义驱动兼容:补齐 kingbase8/kingbasees/kingbasev8 别名归一与写入路径处理 - 回归覆盖:新增 ldf_server.andon_events、转义引号、保留字和大小写标识符测试
99 lines
3.1 KiB
Go
99 lines
3.1 KiB
Go
package app
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"GoNavi-Wails/internal/connection"
|
|
)
|
|
|
|
func TestBuildTableDataClearSQL_TruncateUsesNativeStatementForSupportedDialect(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
sql, err := buildTableDataClearSQL(connection.ConnectionConfig{Type: "mysql"}, "sales.orders", tableDataClearModeTruncate)
|
|
if err != nil {
|
|
t.Fatalf("buildTableDataClearSQL() unexpected error: %v", err)
|
|
}
|
|
|
|
if sql != "TRUNCATE TABLE `sales`.`orders`" {
|
|
t.Fatalf("unexpected truncate sql: %s", sql)
|
|
}
|
|
}
|
|
|
|
func TestBuildTableDataClearSQL_ClearUsesDeleteForCustomMySQLDriver(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
sql, err := buildTableDataClearSQL(connection.ConnectionConfig{Type: "custom", Driver: "mysql"}, "orders", tableDataClearModeDeleteAll)
|
|
if err != nil {
|
|
t.Fatalf("buildTableDataClearSQL() unexpected error: %v", err)
|
|
}
|
|
|
|
if sql != "DELETE FROM `orders`" {
|
|
t.Fatalf("unexpected delete sql for custom mysql driver: %s", sql)
|
|
}
|
|
}
|
|
|
|
func TestBuildTableDataClearSQL_ClearUsesMongoDeleteCommand(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
sql, err := buildTableDataClearSQL(connection.ConnectionConfig{Type: "mongodb"}, "logs", tableDataClearModeDeleteAll)
|
|
if err != nil {
|
|
t.Fatalf("buildTableDataClearSQL() unexpected error: %v", err)
|
|
}
|
|
|
|
if sql != `{"delete":"logs","deletes":[{"q":{},"limit":0}]}` {
|
|
t.Fatalf("unexpected mongo clear command: %s", sql)
|
|
}
|
|
}
|
|
|
|
func TestBuildTableDataClearSQL_KingbaseTruncateNormalizesQuotedQualifiedTable(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
sql, err := buildTableDataClearSQL(connection.ConnectionConfig{Type: "kingbase"}, `\"Idf_server\".\"mes_bip_wip_finished\"`, tableDataClearModeTruncate)
|
|
if err != nil {
|
|
t.Fatalf("buildTableDataClearSQL() unexpected error: %v", err)
|
|
}
|
|
|
|
if sql != `TRUNCATE TABLE "Idf_server".mes_bip_wip_finished` {
|
|
t.Fatalf("unexpected kingbase truncate sql: %s", sql)
|
|
}
|
|
}
|
|
|
|
func TestBuildTableDataClearSQL_KingbaseTruncateLeavesLowercaseQualifiedTableUnquoted(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
sql, err := buildTableDataClearSQL(connection.ConnectionConfig{Type: "kingbase"}, "ldf_server.andon_events", tableDataClearModeTruncate)
|
|
if err != nil {
|
|
t.Fatalf("buildTableDataClearSQL() unexpected error: %v", err)
|
|
}
|
|
|
|
if sql != "TRUNCATE TABLE ldf_server.andon_events" {
|
|
t.Fatalf("unexpected kingbase truncate sql: %s", sql)
|
|
}
|
|
}
|
|
|
|
func TestBuildTableDataClearSQL_KingbaseClearNormalizesQuotedQualifiedTable(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
sql, err := buildTableDataClearSQL(connection.ConnectionConfig{Type: "kingbase"}, `\"Idf_server\".\"mes_bip_wip_finished\"`, tableDataClearModeDeleteAll)
|
|
if err != nil {
|
|
t.Fatalf("buildTableDataClearSQL() unexpected error: %v", err)
|
|
}
|
|
|
|
if sql != `DELETE FROM "Idf_server".mes_bip_wip_finished` {
|
|
t.Fatalf("unexpected kingbase clear sql: %s", sql)
|
|
}
|
|
}
|
|
|
|
func TestBuildTableDataClearSQL_TruncateRejectsUnsupportedDialect(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
_, err := buildTableDataClearSQL(connection.ConnectionConfig{Type: "sqlite"}, "orders", tableDataClearModeTruncate)
|
|
if err == nil {
|
|
t.Fatal("expected truncate to reject sqlite")
|
|
}
|
|
if !strings.Contains(err.Error(), "不支持截断表") {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
}
|