mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-05-12 02:49:42 +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-* 覆盖子目录
66 lines
1.6 KiB
Go
66 lines
1.6 KiB
Go
package logger
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"testing"
|
|
)
|
|
|
|
func TestErrorChain_NilError(t *testing.T) {
|
|
if got := ErrorChain(nil); got != "" {
|
|
t.Errorf("ErrorChain(nil) = %q; want empty string", got)
|
|
}
|
|
}
|
|
|
|
func TestErrorChain_SingleError(t *testing.T) {
|
|
err := errors.New("single error")
|
|
got := ErrorChain(err)
|
|
if got != "single error" {
|
|
t.Errorf("ErrorChain(single) = %q; want %q", got, "single error")
|
|
}
|
|
}
|
|
|
|
func TestErrorChain_WrappedErrors(t *testing.T) {
|
|
inner := errors.New("root cause")
|
|
middle := fmt.Errorf("middle: %w", inner)
|
|
outer := fmt.Errorf("outer: %w", middle)
|
|
|
|
got := ErrorChain(outer)
|
|
// Should contain all three distinct messages
|
|
if got == "" {
|
|
t.Fatal("ErrorChain returned empty string for wrapped errors")
|
|
}
|
|
// The chain should start with the outermost error
|
|
if len(got) < len("outer:") {
|
|
t.Errorf("ErrorChain result too short: %q", got)
|
|
}
|
|
}
|
|
|
|
func TestErrorChain_DeduplicatesMessages(t *testing.T) {
|
|
// Create a chain where wrapping doesn't add new text
|
|
inner := errors.New("same message")
|
|
outer := fmt.Errorf("%w", inner)
|
|
|
|
got := ErrorChain(outer)
|
|
// Should not repeat "same message"
|
|
if got != "same message" {
|
|
t.Errorf("ErrorChain should deduplicate: got %q", got)
|
|
}
|
|
}
|
|
|
|
func TestErrorChain_TruncatesLongChain(t *testing.T) {
|
|
// Build a chain of 25 errors (exceeds the 20-level limit)
|
|
var err error = errors.New("base")
|
|
for i := 0; i < 25; i++ {
|
|
err = fmt.Errorf("level-%d: %w", i, err)
|
|
}
|
|
got := ErrorChain(err)
|
|
if got == "" {
|
|
t.Fatal("ErrorChain returned empty for long chain")
|
|
}
|
|
// Should contain truncation notice
|
|
if len(got) == 0 {
|
|
t.Error("expected non-empty result for long chain")
|
|
}
|
|
}
|