mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-05-18 01:27:35 +08:00
- 校验可选 driver-agent revision,避免重装后复用旧代理 - DuckDB 表预览默认不再追加兜底 ORDER BY - 优化 DuckDB 超时中断提示并补充回归测试
147 lines
4.2 KiB
Go
147 lines
4.2 KiB
Go
package app
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"GoNavi-Wails/internal/connection"
|
|
"GoNavi-Wails/internal/db"
|
|
)
|
|
|
|
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 TestOptionalDriverAgentRevisionCurrentRejectsStaleMetadata(t *testing.T) {
|
|
originalProbe := optionalDriverAgentMetadataProbe
|
|
t.Cleanup(func() {
|
|
optionalDriverAgentMetadataProbe = originalProbe
|
|
})
|
|
optionalDriverAgentMetadataProbe = func(driverType string, executablePath string) (db.OptionalDriverAgentMetadata, error) {
|
|
return db.OptionalDriverAgentMetadata{
|
|
DriverType: driverType,
|
|
AgentRevision: "src-stale-agent",
|
|
}, nil
|
|
}
|
|
|
|
for _, driverType := range optionalDriverAgentRevisionTestDrivers(t) {
|
|
t.Run(driverType, func(t *testing.T) {
|
|
actual, current, err := optionalDriverAgentRevisionCurrent(driverType, "fake-driver-agent")
|
|
if err != nil {
|
|
t.Fatalf("expected stale metadata to be comparable, got error: %v", err)
|
|
}
|
|
if current {
|
|
t.Fatalf("expected stale %s agent revision to be rejected", driverType)
|
|
}
|
|
if actual != "src-stale-agent" {
|
|
t.Fatalf("unexpected actual revision: %q", actual)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestVerifyInstalledOptionalDriverAgentRevisionRejectsProbeFailure(t *testing.T) {
|
|
originalProbe := optionalDriverAgentMetadataProbe
|
|
t.Cleanup(func() {
|
|
optionalDriverAgentMetadataProbe = originalProbe
|
|
})
|
|
optionalDriverAgentMetadataProbe = func(driverType string, executablePath string) (db.OptionalDriverAgentMetadata, error) {
|
|
return db.OptionalDriverAgentMetadata{}, errOptionalDriverAgentMetadataUnavailable
|
|
}
|
|
|
|
for _, driverType := range optionalDriverAgentRevisionTestDrivers(t) {
|
|
t.Run(driverType, func(t *testing.T) {
|
|
if _, err := verifyInstalledOptionalDriverAgentRevision(driverType, "fake-driver-agent"); err == nil {
|
|
t.Fatalf("expected %s install verification to fail when metadata probe fails", driverType)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func optionalDriverAgentRevisionTestDrivers(t *testing.T) []string {
|
|
t.Helper()
|
|
drivers := []string{
|
|
"mariadb",
|
|
"oceanbase",
|
|
"diros",
|
|
"sphinx",
|
|
"sqlserver",
|
|
"sqlite",
|
|
"duckdb",
|
|
"dameng",
|
|
"kingbase",
|
|
"highgo",
|
|
"vastbase",
|
|
"opengauss",
|
|
"mongodb",
|
|
"tdengine",
|
|
"clickhouse",
|
|
}
|
|
for _, driverType := range drivers {
|
|
if db.OptionalDriverAgentRevision(driverType) == "" {
|
|
t.Fatalf("expected %s to define an agent revision", driverType)
|
|
}
|
|
}
|
|
return drivers
|
|
}
|
|
|
|
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)
|
|
}
|
|
}
|