跳到主要内容

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

浏览文件

start_test.go

70 行 · 1.6 KB历史下载
1// SPDX-FileCopyrightText: Copyright The Lima Authors
2// SPDX-License-Identifier: Apache-2.0
3
4package main
5
6import (
7 "os"
8 "path/filepath"
9 "testing"
10
11 "github.com/spf13/cobra"
12 "gotest.tools/v3/assert"
13
14 "github.com/lima-vm/lima/v2/pkg/limatype/filenames"
15)
16
17func TestLoadOrCreateInstance(t *testing.T) {
18 tests := []struct {
19 name string
20 yaml string
21 wantCPUs int
22 wantErrContains []string
23 }{
24 {
25 name: "valid configuration",
26 yaml: "images: [{location: /}]\ncpus: 2\n",
27 wantCPUs: 2,
28 },
29 {
30 name: "invalid configuration",
31 yaml: "arch: [invalid\n",
32 wantErrContains: []string{
33 `instance "test" has configuration errors`,
34 "failed to unmarshal YAML",
35 },
36 },
37 }
38
39 for _, tt := range tests {
40 t.Run(tt.name, func(t *testing.T) {
41 limaDir := t.TempDir()
42 t.Setenv("LIMA_HOME", limaDir)
43 instanceDir := filepath.Join(limaDir, "test")
44 assert.NilError(t, os.MkdirAll(instanceDir, 0o700))
45 assert.NilError(t, os.WriteFile(filepath.Join(instanceDir, filenames.LimaYAML), []byte(tt.yaml), 0o600))
46
47 inst, err := loadOrCreateInstance(newTestStartCommand(t), []string{"test"}, false)
48 if len(tt.wantErrContains) > 0 {
49 for _, want := range tt.wantErrContains {
50 assert.ErrorContains(t, err, want)
51 }
52 assert.Assert(t, inst == nil)
53 return
54 }
55
56 assert.NilError(t, err)
57 assert.Assert(t, inst != nil)
58 assert.Assert(t, inst.Config != nil)
59 assert.Equal(t, *inst.Config.CPUs, tt.wantCPUs)
60 })
61 }
62}
63
64func newTestStartCommand(t *testing.T) *cobra.Command {
65 t.Helper()
66 cmd := newStartCommand()
67 cmd.Flags().Bool("tty", false, "")
68 cmd.SetContext(t.Context())
69 return cmd
70}