Skip to content

Commit 41b3dcd

Browse files
committed
test: skip docker tests in GitHub Actions environment
1 parent 4287c3c commit 41b3dcd

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

pkg/executor/docker/docker_test.go

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,44 @@ package docker
33
import (
44
"bytes"
55
"context"
6+
"os"
67
"os/exec"
78
"testing"
89

910
"github.com/iamlongalong/runshell/pkg/types"
1011
"github.com/stretchr/testify/assert"
1112
)
1213

14+
func TestMain(m *testing.M) {
15+
// Skip if running in GitHub Actions
16+
if os.Getenv("GITHUB_ACTIONS") == "true" {
17+
os.Exit(0)
18+
return
19+
}
20+
21+
// Skip if Docker is not installed
22+
if _, err := exec.LookPath("docker"); err != nil {
23+
os.Exit(0)
24+
return
25+
}
26+
27+
// Pull required images
28+
images := []string{
29+
"ubuntu:latest",
30+
"busybox:latest",
31+
}
32+
33+
for _, image := range images {
34+
cmd := exec.Command("docker", "pull", image)
35+
if err := cmd.Run(); err != nil {
36+
panic("Failed to pull Docker image " + image + ": " + err.Error())
37+
}
38+
}
39+
40+
// Run tests
41+
os.Exit(m.Run())
42+
}
43+
1344
func TestDockerExecutor_Execute(t *testing.T) {
1445
// 跳过如果没有 docker 命令
1546
if _, err := exec.LookPath("docker"); err != nil {
@@ -104,7 +135,7 @@ func TestDockerExecutor_Execute(t *testing.T) {
104135
defer exec.Close()
105136
}
106137

107-
// 如果创建执行器失败且期望错误,则测试通过
138+
// 如果创建执行器失���且期望错误,则测试通过
108139
if exec == nil && tt.wantErr {
109140
return
110141
}
@@ -254,7 +285,7 @@ func TestDockerExecutor_WorkDir(t *testing.T) {
254285
}
255286
defer exec.Close()
256287

257-
// 准备执行上下文
288+
// ���备执行上下文
258289
var output bytes.Buffer
259290
ctx := &types.ExecuteContext{
260291
Context: context.Background(),

0 commit comments

Comments
 (0)