forked from testcontainers/testcontainers-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testing.go
42 lines (36 loc) · 1.36 KB
/
testing.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package testcontainers
import (
"context"
"testing"
"github.com/testcontainers/testcontainers-go/internal/testcontainersdocker"
)
// SkipIfProviderIsNotHealthy is a utility function capable of skipping tests
// if the provider is not healthy, or running at all.
// This is a function designed to be used in your test, when Docker is not mandatory for CI/CD.
// In this way tests that depend on Testcontainers won't run if the provider is provisioned correctly.
func SkipIfProviderIsNotHealthy(t *testing.T) {
ctx := context.Background()
provider, err := ProviderDocker.GetProvider()
if err != nil {
t.Skipf("Docker is not running. TestContainers can't perform is work without it: %s", err)
}
err = provider.Health(ctx)
if err != nil {
t.Skipf("Docker is not running. TestContainers can't perform is work without it: %s", err)
}
}
// SkipIfDockerDesktop is a utility function capable of skipping tests
// if tests are run using Docker Desktop.
func SkipIfDockerDesktop(t *testing.T, ctx context.Context) {
cli, err := testcontainersdocker.NewClient(ctx)
if err != nil {
t.Fatalf("failed to create docker client: %s", err)
}
info, err := cli.Info(ctx)
if err != nil {
t.Fatalf("failed to get docker info: %s", err)
}
if info.OperatingSystem == "Docker Desktop" {
t.Skip("Skipping test that requires host network access when running in Docker Desktop")
}
}