mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-08-10 16:53:35 +08:00
- 移除 99 个仅读取同包 .go 源码做字符串包含断言的测试函数,共 3746 行 - 判据为函数内出现 os.ReadFile 读取 .go 文件且剥离字符串字面量后不调用任何生产代码 - 保留 2 个同时调用生产接口的测试函数,清理 45 个文件中失去引用的 import - go build、go vet 通过,测试失败集合由 40 项减至 39 项且无新增,减少项为已长期失败的墓碑用例
77 lines
1.5 KiB
Go
77 lines
1.5 KiB
Go
package ssh
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"testing"
|
|
"unicode"
|
|
"GoNavi-Wails/internal/connection"
|
|
)
|
|
|
|
func TestSSHConnectionFailureWrappersUseEnglish(t *testing.T) {
|
|
t.Cleanup(CloseAllSSHClients)
|
|
|
|
config := connection.SSHConfig{
|
|
Host: "127.0.0.1",
|
|
Port: 1,
|
|
User: "root",
|
|
Password: "password",
|
|
}
|
|
|
|
cases := []struct {
|
|
name string
|
|
run func() error
|
|
}{
|
|
{
|
|
name: "context dial",
|
|
run: func() error {
|
|
_, err := DialContextThroughSSH(context.Background(), config, "tcp", "127.0.0.1:3306")
|
|
return err
|
|
},
|
|
},
|
|
{
|
|
name: "direct dial",
|
|
run: func() error {
|
|
_, err := DialThroughSSH(config, "tcp", "127.0.0.1:3306")
|
|
return err
|
|
},
|
|
},
|
|
{
|
|
name: "local forwarder",
|
|
run: func() error {
|
|
_, err := NewLocalForwarder(config, "127.0.0.1", 3306)
|
|
return err
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, tc := range cases {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
err := tc.run()
|
|
if err == nil {
|
|
t.Fatalf("expected SSH connection failure")
|
|
}
|
|
message := err.Error()
|
|
if containsHan(message) {
|
|
t.Fatalf("expected English wrapper without Han characters, got %q", message)
|
|
}
|
|
if !strings.Contains(message, "failed to establish SSH connection") {
|
|
t.Fatalf("expected English SSH connection wrapper, got %q", message)
|
|
}
|
|
if !strings.Contains(message, "127.0.0.1:1") {
|
|
t.Fatalf("expected raw SSH address to stay in detail, got %q", message)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
|
|
func containsHan(text string) bool {
|
|
for _, r := range text {
|
|
if unicode.Is(unicode.Han, r) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|