MCPcopy Create free account
hub / github.com/astercloud/aster / testVolcengine

Function testVolcengine

examples/cloud-sandbox/main.go:105–177  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

103}
104
105func testVolcengine(ctx context.Context) {
106 fmt.Println("=== Testing Volcengine Sandbox ===")
107
108 // 创建火山引擎沙箱
109 config := &cloud.VolcengineConfig{
110 Endpoint: os.Getenv("VOLCENGINE_ENDPOINT"),
111 AccessKey: os.Getenv("VOLCENGINE_ACCESS_KEY"),
112 SecretKey: os.Getenv("VOLCENGINE_SECRET_KEY"),
113 Region: "cn-beijing",
114 WorkDir: "/workspace",
115 CPU: 2,
116 Memory: 4096,
117 }
118
119 sb, err := cloud.NewVolcengineSandbox(config)
120 if err != nil {
121 log.Fatalf("Failed to create Volcengine sandbox: %v", err)
122 }
123 defer func() { _ = sb.Dispose() }()
124
125 fmt.Printf("Sandbox created: %s\n", sb.Kind())
126 fmt.Printf("Session ID: %s\n\n", sb.SessionID())
127
128 // 测试 1: 执行命令
129 fmt.Println("--- Test 1: Execute command ---")
130 result, err := sb.Exec(ctx, "echo 'Hello from Volcengine Sandbox'", nil)
131 if err != nil {
132 log.Fatalf("Exec failed: %v", err)
133 }
134 fmt.Printf("Stdout: %s\n", result.Stdout)
135 if result.Stderr != "" {
136 fmt.Printf("Stderr: %s\n", result.Stderr)
137 }
138 fmt.Printf("Exit Code: %d\n\n", result.Code)
139
140 // 测试 2: 写入文件
141 fmt.Println("--- Test 2: Write file ---")
142 fs := sb.FS()
143 err = fs.Write(ctx, "test.txt", "Hello World from Volcengine")
144 if err != nil {
145 log.Fatalf("Write failed: %v", err)
146 }
147 fmt.Println("File written successfully")
148
149 // 测试 3: 读取文件
150 fmt.Println("--- Test 3: Read file ---")
151 content, err := fs.Read(ctx, "test.txt")
152 if err != nil {
153 log.Fatalf("Read failed: %v", err)
154 }
155 fmt.Printf("Content: %s\n\n", content)
156
157 // 测试 4: 获取文件信息
158 fmt.Println("--- Test 4: File info ---")
159 info, err := fs.Stat(ctx, "test.txt")
160 if err != nil {
161 log.Fatalf("Stat failed: %v", err)
162 }

Callers 1

mainFunction · 0.85

Calls 11

DisposeMethod · 0.95
KindMethod · 0.95
ExecMethod · 0.95
FSMethod · 0.95
NewVolcengineSandboxFunction · 0.92
PrintfMethod · 0.80
SessionIDMethod · 0.65
WriteMethod · 0.65
ReadMethod · 0.65
StatMethod · 0.65
GlobMethod · 0.65

Tested by

no test coverage detected