跳到主要内容

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

浏览文件

copy.bats

146 行 · 5.6 KB历史下载
1# SPDX-FileCopyrightText: Copyright The Lima Authors
2# SPDX-License-Identifier: Apache-2.0
3
4load "../helpers/load"
5
6INSTANCE=bats
7
8setup() {
9 limactl shell "$INSTANCE" -- mkdir -p /tmp/test_limactl_copy
10}
11
12teardown() {
13 limactl shell "$INSTANCE" -- rm -rf /tmp/test_limactl_copy
14}
15
16test_copy_dir_from_host_to_instance() {
17 backend="$1"
18 mkdir -p "$BATS_TEST_TMPDIR/foo/bar"
19
20 # SRC DST
21 limactl copy --backend="$backend" -r "$BATS_TEST_TMPDIR/foo" "$INSTANCE":/tmp/test_limactl_copy/foo
22 limactl shell "$INSTANCE" -- test -d /tmp/test_limactl_copy/foo/bar
23 limactl shell "$INSTANCE" -- rm -rf /tmp/test_limactl_copy/foo
24
25 # SRC/ DST
26 limactl shell "$INSTANCE" -- mkdir -p /tmp/test_limactl_copy/foo_src_with_slash/
27 limactl copy --backend="$backend" -r "$BATS_TEST_TMPDIR/foo/" "$INSTANCE":/tmp/test_limactl_copy/foo_src_with_slash
28 limactl shell "$INSTANCE" -- test -d /tmp/test_limactl_copy/foo_src_with_slash/foo
29 limactl shell "$INSTANCE" -- rm -rf /tmp/test_limactl_copy/foo_src_with_slash
30
31 # SRC DST/
32 limactl shell "$INSTANCE" -- mkdir -p /tmp/test_limactl_copy/foo_dst_with_slash/
33 limactl copy --backend="$backend" -r "$BATS_TEST_TMPDIR/foo" "$INSTANCE":/tmp/test_limactl_copy/foo_dst_with_slash/
34 limactl shell "$INSTANCE" -- test -d /tmp/test_limactl_copy/foo_dst_with_slash/foo
35 limactl shell "$INSTANCE" -- rm -rf /tmp/test_limactl_copy/foo_dst_with_slash
36
37 # SRC/ DST/
38 limactl shell "$INSTANCE" -- mkdir -p /tmp/test_limactl_copy/foo_src_dst_with_slash/
39 limactl copy --backend="$backend" -r "$BATS_TEST_TMPDIR/foo/" "$INSTANCE":/tmp/test_limactl_copy/foo_src_dst_with_slash/
40 limactl shell "$INSTANCE" -- test -d /tmp/test_limactl_copy/foo_src_dst_with_slash/foo
41 limactl shell "$INSTANCE" -- rm -rf /tmp/test_limactl_copy/foo_src_dst_with_slash
42
43 # SRC DST, with DST existing: SRC has to be copied into DST, like `cp -r` does.
44 # https://github.com/lima-vm/lima/issues/5500
45 limactl shell "$INSTANCE" -- mkdir -p /tmp/test_limactl_copy/existing_dst
46 limactl copy --backend="$backend" -r "$BATS_TEST_TMPDIR/foo" "$INSTANCE":/tmp/test_limactl_copy/existing_dst
47 limactl shell "$INSTANCE" -- test -d /tmp/test_limactl_copy/existing_dst/foo/bar
48 limactl shell "$INSTANCE" -- rm -rf /tmp/test_limactl_copy/existing_dst
49}
50
51@test "copy directory from host to Lima instance (scp)" {
52 test_copy_dir_from_host_to_instance scp
53}
54
55# https://github.com/lima-vm/lima/issues/4468
56@test "copy directory from host to Lima instance (rsync)" {
57 test_copy_dir_from_host_to_instance rsync
58}
59
60test_copy_dir_from_instance_to_host() {
61 backend="$1"
62
63 limactl shell "$INSTANCE" -- mkdir -p /tmp/test_limactl_copy/foo/bar
64
65 # SRC DST
66 limactl copy --backend="$backend" -r "$INSTANCE":/tmp/test_limactl_copy/foo "$BATS_TEST_TMPDIR/foo"
67 assert_dir_exists "$BATS_TEST_TMPDIR/foo/bar"
68
69 # SRC/ DST
70 limactl copy --backend="$backend" -r "$INSTANCE":/tmp/test_limactl_copy/foo/ "$BATS_TEST_TMPDIR/foo_src_with_slash"
71 assert_dir_exists "$BATS_TEST_TMPDIR/foo_src_with_slash/bar"
72
73 # SRC DST/
74 limactl copy --backend="$backend" -r "$INSTANCE":/tmp/test_limactl_copy/foo "$BATS_TEST_TMPDIR/foo_dst_with_slash/"
75 assert_dir_exists "$BATS_TEST_TMPDIR/foo_dst_with_slash/bar"
76
77 # SRC/ DST/
78 limactl copy --backend="$backend" -r "$INSTANCE":/tmp/test_limactl_copy/foo/ "$BATS_TEST_TMPDIR/foo_src_dst_with_slash/"
79 assert_dir_exists "$BATS_TEST_TMPDIR/foo_src_dst_with_slash/bar"
80
81 # SRC DST, with DST existing: SRC has to be copied into DST, like `cp -r` does.
82 # https://github.com/lima-vm/lima/issues/5500
83 mkdir -p "$BATS_TEST_TMPDIR/existing_dst"
84 limactl copy --backend="$backend" -r "$INSTANCE":/tmp/test_limactl_copy/foo "$BATS_TEST_TMPDIR/existing_dst"
85 assert_dir_exists "$BATS_TEST_TMPDIR/existing_dst/foo/bar"
86}
87
88@test "copy directory from Lima instance to host (scp)" {
89 test_copy_dir_from_instance_to_host scp
90}
91
92@test "copy directory from Lima instance to host (rsync)" {
93 test_copy_dir_from_instance_to_host rsync
94}
95
96test_copy_file_from_host_to_instance() {
97 backend="$1"
98 echo "hello" > "$BATS_TEST_TMPDIR/hello.txt"
99
100 limactl copy --backend="$backend" "$BATS_TEST_TMPDIR/hello.txt" "$INSTANCE":/tmp/test_limactl_copy/hello.txt
101
102 run -0 limactl shell "$INSTANCE" -- cat /tmp/test_limactl_copy/hello.txt
103 assert_output "hello"
104
105 limactl shell "$INSTANCE" -- rm -f /tmp/test_limactl_copy/hello.txt
106}
107
108@test "copy file from host to Lima instance (scp)" {
109 test_copy_file_from_host_to_instance scp
110}
111
112@test "copy file from host to Lima instance (rsync)" {
113 test_copy_file_from_host_to_instance rsync
114}
115
116test_copy_file_from_instance_to_host() {
117 backend="$1"
118 limactl shell "$INSTANCE" -- bash -c 'echo "hello" > /tmp/test_limactl_copy/hello.txt'
119
120 limactl copy --backend="$backend" "$INSTANCE":/tmp/test_limactl_copy/hello.txt "$BATS_TEST_TMPDIR/hello.txt"
121
122 run -0 cat "$BATS_TEST_TMPDIR/hello.txt"
123 assert_output "hello"
124
125 limactl shell "$INSTANCE" -- rm -f /tmp/hello.txt
126}
127
128@test "copy file from Lima instance to host (scp)" {
129 test_copy_file_from_instance_to_host scp
130}
131
132@test "copy file from Lima instance to host (rsync)" {
133 test_copy_file_from_instance_to_host rsync
134}
135
136@test "copy file from Lima instance to Lima instance (auto)" {
137 limactl shell "$INSTANCE" -- bash -c 'echo "hello" > /tmp/test_limactl_copy/hello.txt'
138
139 limactl copy --backend=auto \
140 "$INSTANCE":/tmp/test_limactl_copy/hello.txt \
141 "$INSTANCE":/tmp
142
143 run -0 limactl shell "$INSTANCE" -- cat /tmp/hello.txt
144 assert_output "hello"
145 run -0 limactl shell "$INSTANCE" -- rm -f /tmp/hello.txt
146}