Files
MyGoNavi/internal/app/methods_driver_agent_revision_test.go
Syngnat c927e33c8c feat(driver): 提醒重装旧版驱动代理
- optional-driver-agent 新增 metadata 方法返回 driverType、agentRevision 与协议版本
- 安装和本地导入驱动后记录 agentRevision,并在驱动状态中比对是否需要更新
- 驱动管理、连接表单和已有连接加载入口提示重装旧版 agent
- 补充旧 revision 检测和 custom 连接使用统计回归测试
2026-04-29 17:26:16 +08:00

73 lines
2.0 KiB
Go

package app
import (
"strings"
"testing"
"GoNavi-Wails/internal/connection"
)
func TestOptionalDriverAgentRevisionStatusDetectsStaleClickHouseAgent(t *testing.T) {
needsUpdate, reason, expected := optionalDriverAgentRevisionStatus("clickhouse", installedDriverPackage{}, true)
if !needsUpdate {
t.Fatal("expected missing ClickHouse agent revision to require update")
}
if expected == "" {
t.Fatal("expected ClickHouse to define an agent revision")
}
if reason == "" {
t.Fatal("expected update reason")
}
if !strings.Contains(reason, "原因:") || !strings.Contains(reason, "影响:") {
t.Fatalf("expected reason to explain cause and impact, got %q", reason)
}
if !strings.Contains(reason, "强烈建议重装") {
t.Fatalf("expected reason to strongly recommend reinstall, got %q", reason)
}
current := installedDriverPackage{AgentRevision: expected}
needsUpdate, reason, _ = optionalDriverAgentRevisionStatus("clickhouse", current, true)
if needsUpdate {
t.Fatalf("expected current ClickHouse agent revision to be accepted, reason=%q", reason)
}
}
func TestSavedConnectionDriverUsageCountsIncludesOptionalAndCustomDrivers(t *testing.T) {
app := &App{configDir: t.TempDir()}
repo := app.savedConnectionRepository()
if err := repo.saveAll([]connection.SavedConnectionView{
{
ID: "conn-clickhouse",
Name: "ClickHouse",
Config: connection.ConnectionConfig{
Type: "clickhouse",
},
},
{
ID: "conn-custom-clickhouse",
Name: "Custom ClickHouse",
Config: connection.ConnectionConfig{
Type: "custom",
Driver: "clickhouse",
},
},
{
ID: "conn-mysql",
Name: "MySQL",
Config: connection.ConnectionConfig{
Type: "mysql",
},
},
}); err != nil {
t.Fatalf("save connections failed: %v", err)
}
counts := app.savedConnectionDriverUsageCounts()
if got := counts["clickhouse"]; got != 2 {
t.Fatalf("expected two ClickHouse usages, got %d", got)
}
if got := counts["mysql"]; got != 0 {
t.Fatalf("expected built-in MySQL to be ignored, got %d", got)
}
}