跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

reversesshfs_test.go

80 行 · 1.8 KB历史下载
1package reversesshfs
2
3import (
4 "os"
5 "os/exec"
6 "runtime"
7 "testing"
8 "time"
9)
10
11// TestHelperProcess is a child that waits to be killed, for TestCloseReaps.
12func TestHelperProcess(t *testing.T) {
13 if os.Getenv("REVERSESSHFS_TEST_SLEEP") == "" {
14 return
15 }
16 time.Sleep(time.Minute)
17}
18
19// Close kills the processes and reaps them: a killed child left unwaited stays a zombie, with its pipes.
20func TestCloseReaps(t *testing.T) {
21 start := func() *exec.Cmd {
22 cmd := exec.Command(os.Args[0], "-test.run=^TestHelperProcess$")
23 cmd.Env = append(os.Environ(), "REVERSESSHFS_TEST_SLEEP=1")
24 if err := cmd.Start(); err != nil {
25 t.Fatal(err)
26 }
27 return cmd
28 }
29 rsf := &ReverseSSHFS{sshCmd: start(), opensshSftpServerCmd: start()}
30 if err := rsf.Close(); err != nil {
31 t.Fatal(err)
32 }
33 for _, cmd := range []*exec.Cmd{rsf.sshCmd, rsf.opensshSftpServerCmd} {
34 if cmd.ProcessState == nil {
35 t.Error("a killed process was not waited for")
36 }
37 }
38}
39
40func TestAddQuotes(t *testing.T) {
41 type testCase struct {
42 input string
43 expected string
44 }
45 var testCases []testCase
46 if runtime.GOOS != "windows" {
47 testCases = []testCase{
48 {
49 input: "/user/test/path",
50 expected: "\"/user/test/path\"",
51 },
52 }
53 } else {
54 testCases = []testCase{
55 {
56 input: "/user/test/path",
57 expected: "'/user/test/path'",
58 },
59 }
60 }
61 for i, tc := range testCases {
62 got := addQuotes(tc.input)
63 if got != tc.expected {
64 t.Errorf("#%d: expected %q, got %q", i, tc.expected, got)
65 }
66 }
67}
68
69func TestConvertMSYS2Path(t *testing.T) {
70 inputPath := "/c/Users/lts"
71 expectedPath := "C:\\Users\\lts"
72
73 actualPath := convertMSYS2Path(inputPath)
74
75 if actualPath != expectedPath {
76 t.Errorf("Conversion failed: expected %q, got %q", expectedPath, actualPath)
77 } else {
78 t.Logf("Success! Converted path for native Windows OpenSSH: %q", actualPath)
79 }
80}