mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-06-02 20:49:48 +08:00
- 前端连接表单新增额外连接参数入口,支持 URI query 格式录入与解析回填 - MySQL 兼容驱动支持 JDBC 常见参数映射,修复 UTF-8 字符集与 serverTimezone 兼容问题 - 扩展 Oracle、PostgreSQL 兼容、SQL Server、ClickHouse、MongoDB、达梦、TDengine 参数合并 - 按不同驱动通道处理 DSN、URI、Options 与 Settings,避免统一透传导致连接异常 - 修复编辑已保存连接时解析无认证 URI 会清空已有账号密码的问题 - 补充连接参数透传、缓存隔离、DSN 合并与 URI 回填回归测试
122 lines
2.8 KiB
Go
122 lines
2.8 KiB
Go
package app
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"GoNavi-Wails/internal/connection"
|
|
)
|
|
|
|
func TestGetCacheKey_IgnoreTimeout(t *testing.T) {
|
|
base := connection.ConnectionConfig{
|
|
Type: "duckdb",
|
|
Host: `C:\data\songs.duckdb`,
|
|
Timeout: 30,
|
|
UseProxy: false,
|
|
UseSSH: false,
|
|
}
|
|
modified := base
|
|
modified.Timeout = 120
|
|
|
|
left := getCacheKey(base)
|
|
right := getCacheKey(modified)
|
|
if left != right {
|
|
t.Fatalf("expected same cache key when only timeout differs, got %s vs %s", left, right)
|
|
}
|
|
}
|
|
|
|
func TestGetCacheKey_IgnoreConnectionID(t *testing.T) {
|
|
base := connection.ConnectionConfig{
|
|
ID: "conn-1",
|
|
Type: "mysql",
|
|
Host: "127.0.0.1",
|
|
Port: 3306,
|
|
User: "root",
|
|
Password: "root",
|
|
}
|
|
modified := base
|
|
modified.ID = "conn-2"
|
|
|
|
left := getCacheKey(base)
|
|
right := getCacheKey(modified)
|
|
if left != right {
|
|
t.Fatalf("expected same cache key when only connection id differs, got %s vs %s", left, right)
|
|
}
|
|
}
|
|
|
|
func TestGetCacheKey_DuckDBHostAndDatabaseEquivalent(t *testing.T) {
|
|
withHost := connection.ConnectionConfig{
|
|
Type: "duckdb",
|
|
Host: `D:\music\songs.duckdb`,
|
|
}
|
|
withDatabase := connection.ConnectionConfig{
|
|
Type: "duckdb",
|
|
Database: `D:\music\songs.duckdb`,
|
|
}
|
|
|
|
left := getCacheKey(withHost)
|
|
right := getCacheKey(withDatabase)
|
|
if left != right {
|
|
t.Fatalf("expected same cache key for duckdb host/database path, got %s vs %s", left, right)
|
|
}
|
|
}
|
|
|
|
func TestGetCacheKey_KeepDatabaseIsolation(t *testing.T) {
|
|
a := connection.ConnectionConfig{
|
|
Type: "mysql",
|
|
Host: "127.0.0.1",
|
|
Port: 3306,
|
|
User: "root",
|
|
Password: "root",
|
|
Database: "db_a",
|
|
Timeout: 30,
|
|
}
|
|
b := a
|
|
b.Database = "db_b"
|
|
b.Timeout = 5
|
|
|
|
left := getCacheKey(a)
|
|
right := getCacheKey(b)
|
|
if left == right {
|
|
t.Fatalf("expected different cache key for different database targets")
|
|
}
|
|
}
|
|
|
|
func TestGetCacheKey_KeepConnectionParamsIsolation(t *testing.T) {
|
|
base := connection.ConnectionConfig{
|
|
Type: "mysql",
|
|
Host: "127.0.0.1",
|
|
Port: 3306,
|
|
User: "root",
|
|
Password: "root",
|
|
Database: "app",
|
|
ConnectionParams: "charset=utf8",
|
|
}
|
|
modified := base
|
|
modified.ConnectionParams = "charset=utf8mb4"
|
|
|
|
left := getCacheKey(base)
|
|
right := getCacheKey(modified)
|
|
if left == right {
|
|
t.Fatalf("expected different cache key for different connection params")
|
|
}
|
|
}
|
|
|
|
func TestGetCacheKey_KeepClickHouseProtocolIsolation(t *testing.T) {
|
|
base := connection.ConnectionConfig{
|
|
Type: "clickhouse",
|
|
Host: "clickhouse.local",
|
|
Port: 8125,
|
|
User: "default",
|
|
Database: "default",
|
|
ClickHouseProtocol: "native",
|
|
}
|
|
modified := base
|
|
modified.ClickHouseProtocol = "http"
|
|
|
|
left := getCacheKey(base)
|
|
right := getCacheKey(modified)
|
|
if left == right {
|
|
t.Fatalf("expected different cache key for different ClickHouse protocols")
|
|
}
|
|
}
|