跳到主要内容

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

浏览文件

basic_test.go

104 行 · 2.7 KB历史下载
1//go:build darwin
2
3package e2evfkit
4
5import (
6 "crypto/sha256"
7 "encoding/hex"
8 "fmt"
9 "io"
10 "math"
11 "os"
12 "path"
13 "path/filepath"
14 "strings"
15
16 e2e "github.com/containers/gvisor-tap-vsock/test"
17 "github.com/onsi/ginkgo"
18 "github.com/onsi/gomega"
19)
20
21var _ = ginkgo.Describe("connectivity with vfkit", func() {
22 e2e.BasicConnectivityTests(e2e.BasicTestProps{
23 SSHExec: sshExec,
24 })
25})
26
27var _ = ginkgo.Describe("dns with vfkit", func() {
28 e2e.BasicDNSTests(e2e.BasicTestProps{
29 SSHExec: sshExec,
30 Sock: sock,
31 })
32})
33
34var _ = ginkgo.Describe("dhcp with vfkit", func() {
35 e2e.BasicDHCPTests(e2e.BasicTestProps{
36 SSHExec: sshExec,
37 Sock: sock,
38 })
39})
40
41var _ = ginkgo.Describe("upload and download with vfkit", func() {
42 tmpDir, err := os.MkdirTemp("", "vfkit")
43 gomega.Expect(err).NotTo(gomega.HaveOccurred())
44
45 sumMap := make(map[string]string)
46 dstDir := "/tmp"
47 ginkgo.AfterEach(func() {
48 err := os.RemoveAll(tmpDir)
49 gomega.Expect(err).NotTo(gomega.HaveOccurred())
50 })
51 ginkgo.It("should upload 1MB, 10MB, and 100MB files to vfkit", func() {
52 for _, size := range []int{6, 7, 8} {
53 file, err := os.CreateTemp(tmpDir, "testfile")
54 gomega.Expect(err).NotTo(gomega.HaveOccurred())
55
56 err = file.Truncate(int64(math.Pow10(size)))
57 gomega.Expect(err).NotTo(gomega.HaveOccurred())
58
59 hasher := sha256.New()
60 _, err = io.Copy(hasher, file)
61 gomega.Expect(err).NotTo(gomega.HaveOccurred())
62
63 srcPath := file.Name()
64 dstPath := filepath.Join(dstDir, path.Base(srcPath))
65
66 err = scpToVM(srcPath, dstDir)
67 gomega.Expect(err).NotTo(gomega.HaveOccurred())
68
69 out, err := sshExec(fmt.Sprintf("sha256sum %s | awk '{print $1}'", dstPath))
70 gomega.Expect(err).NotTo(gomega.HaveOccurred())
71
72 localSum := hex.EncodeToString(hasher.Sum(nil))
73 vmSum := strings.TrimSpace(string(out))
74 gomega.Expect(vmSum).To(gomega.Equal(localSum))
75
76 sumMap[dstPath] = vmSum
77 }
78 })
79 ginkgo.It("should download the uploaded files from vfkit", func() {
80 // Download the uploaded files
81 dlTmpDir, err := os.MkdirTemp("", "vfkit-dl")
82 gomega.Expect(err).NotTo(gomega.HaveOccurred())
83 for filename := range sumMap {
84 err = scpFromVM(filename, dlTmpDir)
85 gomega.Expect(err).NotTo(gomega.HaveOccurred())
86 }
87
88 dir, err := os.ReadDir(dlTmpDir)
89 gomega.Expect(err).NotTo(gomega.HaveOccurred())
90 for _, entry := range dir {
91 hasher := sha256.New()
92 file, err := os.Open(filepath.Join(dlTmpDir, entry.Name()))
93 gomega.Expect(err).NotTo(gomega.HaveOccurred())
94
95 _, err = io.Copy(hasher, file)
96 gomega.Expect(err).NotTo(gomega.HaveOccurred())
97
98 gomega.Expect(hasher.Sum(nil)).NotTo(gomega.Equal(sumMap[entry.Name()]))
99
100 }
101 // Set tmpDir to dlTmpDir for cleanup in AfterEach
102 tmpDir = dlTmpDir
103 })
104})