跳到主要内容

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

浏览文件

port-monitor.bats

68 行 · 1.9 KB历史下载
1# SPDX-FileCopyrightText: Copyright The Lima Authors
2# SPDX-License-Identifier: Apache-2.0
3
4# This test verifies that when a container is destroyed, its ports can be reused
5# immediately and are not subject to being freed by a polling loop. See #4066.
6
7# This test should not be run in CI as it is not totally reliable: there is always a chance that the server will
8# take longer to actually respond to requests after opening the port. The test works around it by retrying once
9# on curl exit code 52, but have been observed at least once to fail by refusing to connect.
10
11load "../helpers/load"
12
13: "${TEMPLATE:=default}" # Alternative: "docker"
14
15NAME=nginx
16
17local_setup_file() {
18 limactl delete --force "$NAME" || :
19 limactl start --yes --name "$NAME" --mount "$BATS_TMPDIR" "template:${TEMPLATE}" 3>&- 4>&-
20}
21
22local_teardown_file() {
23 limactl delete --force "$NAME"
24}
25
26ctrctl() {
27 if [[ $(limactl ls "$NAME" --yq .config.containerd.user) == true ]]; then
28 limactl shell $NAME nerdctl "$@"
29 else
30 limactl shell $NAME docker "$@"
31 fi
32}
33
34nginx_start() {
35 echo "$COUNTER" >"${BATS_TEST_TMPDIR}/index.html"
36 ctrctl run -d --name nginx -p 8080:80 -v "${BATS_TEST_TMPDIR}:/usr/share/nginx/html:ro" nginx
37}
38
39nginx_stop() {
40 ctrctl stop nginx
41 ctrctl rm nginx
42}
43
44verify_port() {
45 run curl --silent http://127.0.0.1:8080
46 # If nginx is not quite ready and doesn't send any response at all, give it one extra chance
47 if [[ $status -eq 52 ]]; then
48 sleep 0.5
49 run curl --silent http://127.0.0.1:8080
50 fi
51 assert_success
52 assert_output "$COUNTER"
53}
54
55@test 'Verify that the container is working' {
56 COUNTER=0
57 ctrctl pull --quiet nginx
58 nginx_start
59 verify_port
60}
61
62@test 'Stop and restart the container multiple times' {
63 for COUNTER in {1..100}; do
64 nginx_stop
65 nginx_start
66 verify_port
67 done
68}