Files
MyGoNavi/internal/app/methods_file_ssh_key_test.go
Syngnat 88b427c41a 🔥 remove(go-test): 删除后端读取源码文本断言的测试函数
- 移除 99 个仅读取同包 .go 源码做字符串包含断言的测试函数,共 3746 行
- 判据为函数内出现 os.ReadFile 读取 .go 文件且剥离字符串字面量后不调用任何生产代码
- 保留 2 个同时调用生产接口的测试函数,清理 45 个文件中失去引用的 import
- go build、go vet 通过,测试失败集合由 40 项减至 39 项且无新增,减少项为已长期失败的墓碑用例
2026-07-26 21:37:22 +08:00

44 lines
1.2 KiB
Go

package app
import (
"os"
"path/filepath"
"testing"
)
func TestResolveFileOpenDialogDirectoryHandlesExtensionlessSSHKeys(t *testing.T) {
root := t.TempDir()
sshDir := filepath.Join(root, ".ssh")
if err := os.MkdirAll(sshDir, 0o700); err != nil {
t.Fatalf("mkdir .ssh: %v", err)
}
keyPath := filepath.Join(sshDir, "id_ed25519")
if err := os.WriteFile(keyPath, []byte("-----BEGIN OPENSSH PRIVATE KEY-----\n"), 0o600); err != nil {
t.Fatalf("write key: %v", err)
}
got := resolveFileOpenDialogDirectory(keyPath, filepath.Join(root, "fallback"))
want := absDialogPath(sshDir)
if got != want {
t.Fatalf("existing extensionless key: got %q, want %q", got, want)
}
missingKey := filepath.Join(sshDir, "custom_deploy_key")
got = resolveFileOpenDialogDirectory(missingKey, filepath.Join(root, "fallback"))
if got != want {
t.Fatalf("missing extensionless key: got %q, want %q", got, want)
}
got = resolveFileOpenDialogDirectory("", sshDir)
if got != want {
t.Fatalf("empty current path falls back to .ssh: got %q, want %q", got, want)
}
got = resolveFileOpenDialogDirectory(sshDir, filepath.Join(root, "fallback"))
if got != want {
t.Fatalf("directory path kept as-is: got %q, want %q", got, want)
}
}