重构:完成架构一致性整改与生命周期收口

This commit is contained in:
Christ committed 2026-08-18 14:05:08 +08:00
1 parent 55904cc409
commit 9eb6be2875
344 files changed
+15961 -13926

No files matched your search

+14 -14
View File
@@ -9,9 +9,9 @@ import (
// 关键不变量:SQLite/Postgres 用 ON CONFLICT...DO UPDATE SET,MySQL 用 ON DUPLICATE KEY UPDATE;
// 列名按字典序输出(保证幂等可重现);MySQL 下 EXCLUDED.col 自动改写为 VALUES(col),
// 大小写不敏感;CURRENT_TIMESTAMP 等非 EXCLUDED 表达式原样保留。
// TestDialectUpsert 负责TestDialectUpsert相关处理。
// TestDialectUpsert 封装TestDialectUpsert业务协调。
func TestDialectUpsert(t *testing.T) {
// cases 保存cases,供当前处理流程使用
// cases 用于本次流程后续判断的cases
cases := []struct {
name string
d Dialect
@@ -72,7 +72,7 @@ func TestDialectUpsert(t *testing.T) {
// c 表示当前遍历过程中的c
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
// got 保存got,供当前处理流程使用
// got 用于本次流程后续判断的got
got := DialectUpsert(c.d, c.conflict, c.updates)
if got != c.want {
t.Errorf("DialectUpsert(%s) = %q; want %q", c.d, got, c.want)
@@ -83,9 +83,9 @@ func TestDialectUpsert(t *testing.T) {
// TestDialectInsertIgnore 断言“冲突即忽略”子句:MySQL 恒空(前缀模式负责),
// SQLite/Postgres 生成 ON CONFLICT...DO NOTHING,空 conflictCols 时返回空。
// TestDialectInsertIgnore 负责TestDialectInsertIgnore相关处理。
// TestDialectInsertIgnore 封装TestDialectInsertIgnore业务协调。
func TestDialectInsertIgnore(t *testing.T) {
// cases 保存cases,供当前处理流程使用
// cases 用于本次流程后续判断的cases
cases := []struct {
d Dialect
conflict []string
@@ -99,7 +99,7 @@ func TestDialectInsertIgnore(t *testing.T) {
}
// c 表示当前遍历过程中的c
for _, c := range cases {
// got 保存got,供当前处理流程使用
// got 用于本次流程后续判断的got
got := DialectInsertIgnore(c.d, c.conflict)
if got != c.want {
t.Errorf("DialectInsertIgnore(%s, %v) = %q; want %q", c.d, c.conflict, got, c.want)
@@ -109,15 +109,15 @@ func TestDialectInsertIgnore(t *testing.T) {
// TestDialectInsertIgnorePrefix MySQL 走 INSERT IGNORE,其余走 INSERT。
func TestDialectInsertIgnorePrefix(t *testing.T) {
if // got 保存got,供当前处理流程使用
if // got 用于本次流程后续判断的got
got := DialectInsertIgnorePrefix(DialectMySQL); got != "INSERT IGNORE" {
t.Errorf("mysql prefix = %q; want INSERT IGNORE", got)
}
if // got 保存got,供当前处理流程使用
if // got 用于本次流程后续判断的got
got := DialectInsertIgnorePrefix(DialectSQLite); got != "INSERT" {
t.Errorf("sqlite prefix = %q; want INSERT", got)
}
if // got 保存got,供当前处理流程使用
if // got 用于本次流程后续判断的got
got := DialectInsertIgnorePrefix(DialectPostgres); got != "INSERT" {
t.Errorf("postgres prefix = %q; want INSERT", got)
}
@@ -125,7 +125,7 @@ func TestDialectInsertIgnorePrefix(t *testing.T) {
// TestDialectQuote Postgres 用双引号,SQLite/MySQL 用反引号。
func TestDialectQuote(t *testing.T) {
// cases 保存cases,供当前处理流程使用
// cases 用于本次流程后续判断的cases
cases := []struct {
d Dialect
name string
@@ -138,7 +138,7 @@ func TestDialectQuote(t *testing.T) {
}
// c 表示当前遍历过程中的c
for _, c := range cases {
if // got 保存got,供当前处理流程使用
if // got 用于本次流程后续判断的got
got := DialectQuote(c.d, c.name); got != c.want {
t.Errorf("DialectQuote(%s, %q) = %q; want %q", c.d, c.name, got, c.want)
}
@@ -147,12 +147,12 @@ func TestDialectQuote(t *testing.T) {
// TestSortStrings 确认 sortStrings 原地升序排序(被 DialectUpsert 用于稳定输出顺序)。
func TestSortStrings(t *testing.T) {
// in 保存in,供当前处理流程使用
// in 用于本次流程后续判断的in
in := []string{"banana", "apple", "cherry", "apple"}
sortStrings(in)
// want 保存want,供当前处理流程使用
// want 用于本次流程后续判断的want
want := "apple,apple,banana,cherry"
if // got 保存got,供当前处理流程使用
if // got 用于本次流程后续判断的got
got := strings.Join(in, ","); got != want {
t.Errorf("sortStrings = %q; want %q", got, want)
}