testcontainers / testcontainers-go

Testcontainers for Go is a Go package that makes it simple to create and clean up container-based dependencies for automated integration/smoke tests. The clean, easy-to-use API enables developers to programmatically define containers that should be run as part of a test and clean up those resources when the test is done.
https://golang.testcontainers.org
MIT License
3.68k stars 504 forks source link

[Bug]: `github.com/testcontainers/testcontainers-go.SkipIfProviderIsNotHealthy` panics on GHA `macos-latest` runners #2859

Open RomainMuller opened 3 weeks ago

RomainMuller commented 3 weeks ago

Testcontainers version

0.34.0

Using the latest Testcontainers version?

Yes

Host OS

macOS

Host arch

x86, ARM64

Go version

1.22 / 1.23

Docker version

Docker is not available on macos-latest GitHub Actions runners.

Docker info

Docker is not available on macos-latest GitHub Actions runners.

What happened?

Attempting to skip tests on runners where Docker is not usable using github.com/testcontainers/testcontainers-go.SkipIfProviderIsNotHealthy; tests still fail on an unconditional panic on macos-latest runners in GitHub Actions.

Relevant log output

panic: rootless Docker not found [recovered]
    panic: rootless Docker not found

goroutine 53 [running]:
testing.tRunner.func1.2({0x102f964a0, 0x140001285d0})
    /Users/runner/hostedtoolcache/go/1.22.8/arm64/src/testing/testing.go:1631 +0x1c4
testing.tRunner.func1()
    /Users/runner/hostedtoolcache/go/1.22.8/arm64/src/testing/testing.go:1634 +0x33c
panic({0x102f964a0?, 0x140001285d0?})
    /Users/runner/hostedtoolcache/go/1.22.8/arm64/src/runtime/panic.go:770 +0x124
github.com/testcontainers/testcontainers-go/internal/core.MustExtractDockerHost.func1()
    /Users/runner/go/pkg/mod/github.com/testcontainers/testcontainers-go@v0.34.0/internal/core/docker_host.go:91 +0x78
sync.(*Once).doSlow(0x0?, 0x0?)
    /Users/runner/hostedtoolcache/go/1.22.8/arm64/src/sync/once.go:74 +0x100
sync.(*Once).Do(...)
    /Users/runner/hostedtoolcache/go/1.22.8/arm64/src/sync/once.go:65
github.com/testcontainers/testcontainers-go/internal/core.MustExtractDockerHost({0x103092ec0?, 0x1035f0f80?})
    /Users/runner/go/pkg/mod/github.com/testcontainers/testcontainers-go@v0.34.0/internal/core/docker_host.go:88 +0x5c
github.com/testcontainers/testcontainers-go/internal/core.NewClient({0x103092ec0, 0x1035f0f80}, {0x0, 0x0, 0x0?})
    /Users/runner/go/pkg/mod/github.com/testcontainers/testcontainers-go@v0.34.0/internal/core/client.go:17 +0x9c
github.com/testcontainers/testcontainers-go.NewDockerClientWithOpts({0x103092ec0, 0x1035f0f80}, {0x0, 0x0, 0x0})
    /Users/runner/go/pkg/mod/github.com/testcontainers/testcontainers-go@v0.34.0/docker_client.go:117 +0x4c
github.com/testcontainers/testcontainers-go.NewDockerProvider({0x14000a84c50, 0x1, 0x14000079bf8?})
    /Users/runner/go/pkg/mod/github.com/testcontainers/testcontainers-go@v0.34.0/provider.go:143 +0x10c
github.com/testcontainers/testcontainers-go.ProviderType.GetProvider(0x1, {0x0, 0x0, 0x10288cd40?})
    /Users/runner/go/pkg/mod/github.com/testcontainers/testcontainers-go@v0.34.0/provider.go:114 +0x394
github.com/testcontainers/testcontainers-go.SkipIfProviderIsNotHealthy(0x140007a6d00)
    /Users/runner/go/pkg/mod/github.com/testcontainers/testcontainers-go@v0.34.0/testing.go:24 +0x38
datadoghq.dev/orchestrion/_integration-tests/utils.SkipIfProviderIsNotHealthy(0x140007a6d00)
    /Users/runner/work/orchestrion/orchestrion/_integration-tests/utils/testcontainers.go:103 +0xf0
datadoghq.dev/orchestrion/_integration-tests/tests/vault.(*TestCase).Setup(0x14000a84ba0, 0x140007a6d00)
    /Users/runner/work/orchestrion/orchestrion/_integration-tests/tests/vault/vault.go:30 +0xac
datadoghq.dev/orchestrion/_integration-tests/utils.RunTest(0x140007a6d00, {0x103092ef8, 0x14000a84ba0})
    /Users/runner/work/orchestrion/orchestrion/_integration-tests/utils/suite.go:63 +0x188
datadoghq.dev/orchestrion/_integration-tests/tests/vault.TestIntegration_vault(0x140007a6d00)
    /Users/runner/work/orchestrion/orchestrion/_integration-tests/tests/vault/gen_test.go:18 +0x3c
testing.tRunner(0x140007a6d00, 0x103085a78)
    /Users/runner/hostedtoolcache/go/1.22.8/arm64/src/testing/testing.go:1689 +0xec
created by testing.(*T).Run in goroutine 1
    /Users/runner/hostedtoolcache/go/1.22.8/arm64/src/testing/testing.go:1742 +0x320

Additional information

No response

mdelapenya commented 3 weeks ago

Thanks for opening this issue, yeah the MustExtractDockerHost panics if no docker host/socket is discovered. I think that test helper could be improved to recover on panics and effectively skip the test in that case.

Would you like to work on a fix for that?