跳到主要内容

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

浏览文件

server_nowindows_test.go

87 行 · 1.9 KB历史下载
1//go:build !windows
2// +build !windows
3
4package sftp
5
6import (
7 "testing"
8)
9
10func TestServer_toLocalPath(t *testing.T) {
11 tests := []struct {
12 name string
13 withWorkDir string
14 p string
15 want string
16 }{
17 {
18 name: "empty path with no workdir",
19 p: "",
20 want: "",
21 },
22 {
23 name: "relative path with no workdir",
24 p: "file",
25 want: "file",
26 },
27 {
28 name: "absolute path with no workdir",
29 p: "/file",
30 want: "/file",
31 },
32 {
33 name: "workdir and empty path",
34 withWorkDir: "/home/user",
35 p: "",
36 want: "/home/user",
37 },
38 {
39 name: "workdir and relative path",
40 withWorkDir: "/home/user",
41 p: "file",
42 want: "/home/user/file",
43 },
44 {
45 name: "workdir and relative path with .",
46 withWorkDir: "/home/user",
47 p: ".",
48 want: "/home/user",
49 },
50 {
51 name: "workdir and relative path with . and file",
52 withWorkDir: "/home/user",
53 p: "./file",
54 want: "/home/user/file",
55 },
56 {
57 name: "workdir and absolute path",
58 withWorkDir: "/home/user",
59 p: "/file",
60 want: "/file",
61 },
62 {
63 name: "workdir and non-unixy path prefixes workdir",
64 withWorkDir: "/home/user",
65 p: "C:\\file",
66 // This may look like a bug but it is the result of passing
67 // invalid input (a non-unixy path) to the server.
68 want: "/home/user/C:\\file",
69 },
70 }
71 for _, tt := range tests {
72 t.Run(tt.name, func(t *testing.T) {
73 // We don't need to initialize the Server further to test
74 // toLocalPath behavior.
75 s := &Server{}
76 if tt.withWorkDir != "" {
77 if err := WithServerWorkingDirectory(tt.withWorkDir)(s); err != nil {
78 t.Fatal(err)
79 }
80 }
81
82 if got := s.toLocalPath(tt.p); got != tt.want {
83 t.Errorf("Server.toLocalPath() = %q, want %q", got, tt.want)
84 }
85 })
86 }
87}