feat(core): 下沉查询密码工具与配置快照解码
Verify / verify (push) Canceled after 0s

This commit is contained in:
zhangdeman committed 2026-11-28 03:10:18 -08:00
1 parent bedcf4dd83
commit d2a9033695
23 files changed
+1544 -6

No files matched your search

+51
View File
@@ -0,0 +1,51 @@
package dberror
import (
"context"
"database/sql"
"errors"
"fmt"
"os"
"strings"
"testing"
"github.com/go-sql-driver/mysql"
)
func TestDuplicateKeyAgainstMySQL(t *testing.T) {
dsn := os.Getenv("GINFRAMEWORK_TEST_MYSQL_DSN")
if dsn == "" {
t.Skip("isolated MySQL DSN is not provided")
}
cfg, err := mysql.ParseDSN(dsn)
if err != nil || !strings.HasPrefix(cfg.DBName, "ginframework_test_") {
t.Fatal("isolated ginframework_test_ database is required")
}
db, err := sql.Open("mysql", dsn)
if err != nil {
t.Fatal("open isolated MySQL failed")
}
defer db.Close()
conn, err := db.Conn(context.Background())
if err != nil {
t.Fatal(err)
}
defer conn.Close()
if _, err = conn.ExecContext(context.Background(), "CREATE TEMPORARY TABLE duplicate_probe (id BIGINT PRIMARY KEY, value BIGINT NOT NULL)"); err != nil {
t.Fatal(err)
}
if _, err = conn.ExecContext(context.Background(), "INSERT INTO duplicate_probe (id,value) VALUES (?,?)", 1, 1); err != nil {
t.Fatal(err)
}
_, err = conn.ExecContext(context.Background(), "INSERT INTO duplicate_probe (id,value) VALUES (?,?)", 1, 2)
var (
driverError *mysql.MySQLError
)
if !errors.As(err, &driverError) || driverError.Number != 1062 || !IsDuplicateKey(fmt.Errorf("insert probe: %w", err)) {
t.Fatalf("duplicate cause lost: %T", err)
}
_, err = conn.ExecContext(context.Background(), "INSERT INTO duplicate_probe (id,value) VALUES (?,NULL)", 2)
if err == nil || IsDuplicateKey(err) {
t.Fatal("non-null violation classified as duplicate")
}
}
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.