Skip to content

Commit 9a27dba

Browse files
committed
Add requireDocker helper
1 parent 65cb8c2 commit 9a27dba

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

test/integration/main_test.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
11
package integration_test
22

33
import (
4+
"context"
45
"testing"
56

67
"github.com/docker/docker/client"
78
)
89

910
var dockerClient *client.Client
11+
var dockerAvailable bool
1012

1113
func TestMain(m *testing.M) {
1214
var err error
1315
dockerClient, err = client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
14-
if err != nil {
15-
panic(err)
16+
if err == nil {
17+
_, err = dockerClient.Ping(context.Background())
18+
dockerAvailable = err == nil
1619
}
1720
m.Run()
1821
}
22+
23+
func requireDocker(t *testing.T) {
24+
t.Helper()
25+
if !dockerAvailable {
26+
t.Skip("Docker is not available")
27+
}
28+
}

test/integration/start_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const (
2222
const containerName = "localstack-aws"
2323

2424
func TestStartCommandSucceedsWithValidToken(t *testing.T) {
25+
requireDocker(t)
2526
authToken := os.Getenv("LOCALSTACK_AUTH_TOKEN")
2627
require.NotEmpty(t, authToken, "LOCALSTACK_AUTH_TOKEN must be set to run this test")
2728

@@ -43,6 +44,7 @@ func TestStartCommandSucceedsWithValidToken(t *testing.T) {
4344
}
4445

4546
func TestStartCommandTriggersLoginWithoutToken(t *testing.T) {
47+
requireDocker(t)
4648
cleanup()
4749
t.Cleanup(cleanup)
4850

@@ -80,6 +82,7 @@ func TestStartCommandTriggersLoginWithoutToken(t *testing.T) {
8082
}
8183

8284
func TestStartCommandSucceedsWithKeyringToken(t *testing.T) {
85+
requireDocker(t)
8386
cleanup()
8487
t.Cleanup(cleanup)
8588

@@ -105,6 +108,7 @@ func TestStartCommandSucceedsWithKeyringToken(t *testing.T) {
105108
}
106109

107110
func TestStartCommandFailsWithInvalidToken(t *testing.T) {
111+
requireDocker(t)
108112
cleanup()
109113
t.Cleanup(cleanup)
110114

0 commit comments

Comments
 (0)