mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-05-15 20:37:52 +08:00
- 支持 ClickHouse 手动 HTTP/Native 协议优先级,避免 URI scheme 覆盖用户选择 - Auto 模式识别 Native/HTTP 协议误配错误并自动尝试备用协议 - 净化连接失败中的二进制乱码,补充测试连接参数校验和排查日志 - 前端表单增加 ClickHouse 协议选择并同步类型、缓存 key 与持久化兼容 Refs #425
102 lines
2.3 KiB
Go
102 lines
2.3 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_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")
|
|
}
|
|
}
|