mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-05-11 17:19:45 +08:00
错误消息中文化: - 19 个驱动实现文件中 connection not open / table name required 等英文消息替换为中文 - methods_file.go / methods_db.go / methods_driver.go 英文消息中文化 - 前端 App/Sidebar/DataGrid/ConnectionModal/DriverManagerModal 同步替换 "Cancelled" → "已取消" 文档与测试: - database.go Database/BatchApplier 接口、types.go 12 个类型、driver_support.go 导出函数补充中文 godoc - 新增 logger_test.go(ErrorChain 5 个用例)和 methods_db_conn_test.go(连接管理 7 个用例) Bug 修复: - DataGrid: 将 liveTargets 空检查移至非虚拟路径,修复外部横向滚动条拖动时内容不跟随 - vite.config.ts: server.host 指定 127.0.0.1,修复 IPv6 回环被拦截导致 Wails 代理 502 基础设施: - .gitignore 新增 .gemini/ 规则,tmpclaude-* 改为 **/tmpclaude-* 覆盖子目录
113 lines
2.9 KiB
Go
113 lines
2.9 KiB
Go
package app
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"GoNavi-Wails/internal/connection"
|
|
)
|
|
|
|
func TestNormalizeTestConnectionConfig_CapsTimeout(t *testing.T) {
|
|
cfg := connection.ConnectionConfig{Timeout: 60}
|
|
got := normalizeTestConnectionConfig(cfg)
|
|
if got.Timeout != testConnectionTimeoutUpperBoundSeconds {
|
|
t.Fatalf("timeout 应被限制为 %d, got=%d", testConnectionTimeoutUpperBoundSeconds, got.Timeout)
|
|
}
|
|
}
|
|
|
|
func TestNormalizeTestConnectionConfig_KeepSmallTimeout(t *testing.T) {
|
|
cfg := connection.ConnectionConfig{Timeout: 5}
|
|
got := normalizeTestConnectionConfig(cfg)
|
|
if got.Timeout != 5 {
|
|
t.Fatalf("timeout 不应被修改, got=%d", got.Timeout)
|
|
}
|
|
}
|
|
|
|
func TestNormalizeTestConnectionConfig_ZeroTimeout(t *testing.T) {
|
|
cfg := connection.ConnectionConfig{Timeout: 0}
|
|
got := normalizeTestConnectionConfig(cfg)
|
|
if got.Timeout != testConnectionTimeoutUpperBoundSeconds {
|
|
t.Fatalf("零值 timeout 应被修正, got=%d", got.Timeout)
|
|
}
|
|
}
|
|
|
|
func TestFormatConnSummary_BasicMySQL(t *testing.T) {
|
|
cfg := connection.ConnectionConfig{
|
|
Type: "mysql",
|
|
Host: "127.0.0.1",
|
|
Port: 3306,
|
|
User: "root",
|
|
Database: "test_db",
|
|
Timeout: 30,
|
|
}
|
|
got := formatConnSummary(cfg)
|
|
for _, want := range []string{"类型=mysql", "127.0.0.1:3306", "test_db", "root"} {
|
|
if !strings.Contains(got, want) {
|
|
t.Fatalf("formatConnSummary 应包含 %q, got=%q", want, got)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestFormatConnSummary_SQLitePath(t *testing.T) {
|
|
cfg := connection.ConnectionConfig{
|
|
Type: "sqlite",
|
|
Host: "/data/test.db",
|
|
}
|
|
got := formatConnSummary(cfg)
|
|
if !strings.Contains(got, "类型=sqlite") {
|
|
t.Fatalf("formatConnSummary 缺少类型, got=%q", got)
|
|
}
|
|
if !strings.Contains(got, "/data/test.db") {
|
|
t.Fatalf("formatConnSummary 缺少路径, got=%q", got)
|
|
}
|
|
}
|
|
|
|
func TestFormatConnSummary_SSH(t *testing.T) {
|
|
cfg := connection.ConnectionConfig{
|
|
Type: "mysql",
|
|
Host: "db.internal",
|
|
Port: 3306,
|
|
User: "app",
|
|
UseSSH: true,
|
|
SSH: connection.SSHConfig{
|
|
Host: "jump.server",
|
|
Port: 22,
|
|
User: "admin",
|
|
},
|
|
}
|
|
got := formatConnSummary(cfg)
|
|
if !strings.Contains(got, "SSH=jump.server:22") {
|
|
t.Fatalf("formatConnSummary 应包含 SSH 信息, got=%q", got)
|
|
}
|
|
}
|
|
|
|
func TestFormatConnSummary_Proxy(t *testing.T) {
|
|
cfg := connection.ConnectionConfig{
|
|
Type: "mysql",
|
|
Host: "db.internal",
|
|
Port: 3306,
|
|
UseProxy: true,
|
|
Proxy: connection.ProxyConfig{
|
|
Type: "socks5",
|
|
Host: "proxy.local",
|
|
Port: 1080,
|
|
},
|
|
}
|
|
got := formatConnSummary(cfg)
|
|
if !strings.Contains(got, "代理=socks5://proxy.local:1080") {
|
|
t.Fatalf("formatConnSummary 应包含代理信息, got=%q", got)
|
|
}
|
|
}
|
|
|
|
func TestFormatConnSummary_DefaultTimeout(t *testing.T) {
|
|
cfg := connection.ConnectionConfig{
|
|
Type: "mysql",
|
|
Host: "localhost",
|
|
Port: 3306,
|
|
}
|
|
got := formatConnSummary(cfg)
|
|
if !strings.Contains(got, "超时=30s") {
|
|
t.Fatalf("formatConnSummary 默认超时应为30s, got=%q", got)
|
|
}
|
|
}
|