跳到主要内容

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

浏览文件

disk_test.go

62 行 · 1.7 KB历史下载
1// SPDX-FileCopyrightText: Copyright The Lima Authors
2// SPDX-License-Identifier: Apache-2.0
3
4package store
5
6import (
7 "os"
8 "path/filepath"
9 "testing"
10
11 "gotest.tools/v3/assert"
12
13 "github.com/lima-vm/lima/v2/pkg/limatype/filenames"
14)
15
16func TestDiskLockForInstance(t *testing.T) {
17 t.Run("unlocked disk", func(t *testing.T) {
18 diskDir := t.TempDir()
19 instanceDir := t.TempDir()
20 disk := &Disk{Name: "testdisk", Dir: diskDir}
21
22 assert.NilError(t, disk.LockForInstance(instanceDir))
23 target, err := os.Readlink(filepath.Join(diskDir, filenames.InUseBy))
24 assert.NilError(t, err)
25 assert.Equal(t, target, instanceDir)
26 })
27
28 t.Run("locked by same instance (stale lock)", func(t *testing.T) {
29 diskDir := t.TempDir()
30 instanceDir := t.TempDir()
31 disk := &Disk{
32 Name: "testdisk",
33 Dir: diskDir,
34 Instance: filepath.Base(instanceDir),
35 InstanceDir: instanceDir,
36 }
37 // Simulate stale lock from previous run
38 assert.NilError(t, os.Symlink(instanceDir, filepath.Join(diskDir, filenames.InUseBy)))
39
40 // LockForInstance should auto-unlock and re-lock
41 assert.NilError(t, disk.LockForInstance(instanceDir))
42 target, err := os.Readlink(filepath.Join(diskDir, filenames.InUseBy))
43 assert.NilError(t, err)
44 assert.Equal(t, target, instanceDir)
45 })
46
47 t.Run("locked by different instance", func(t *testing.T) {
48 diskDir := t.TempDir()
49 otherDir := t.TempDir()
50 disk := &Disk{
51 Name: "testdisk",
52 Dir: diskDir,
53 Instance: filepath.Base(otherDir),
54 InstanceDir: otherDir,
55 }
56 assert.NilError(t, os.Symlink(otherDir, filepath.Join(diskDir, filenames.InUseBy)))
57
58 newInstanceDir := t.TempDir()
59 err := disk.LockForInstance(newInstanceDir)
60 assert.ErrorContains(t, err, "in use by instance")
61 })
62}