From 0b4935e6e83c49963a948c11a1f00c0ef4dfe3d1 Mon Sep 17 00:00:00 2001 From: Jason Yu Date: Fri, 10 Jan 2025 09:55:44 -0800 Subject: [PATCH] Recover from panic in SkipIfProviderIsNotHealthy --- testing.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/testing.go b/testing.go index 35ce4f0a39..63dedc259e 100644 --- a/testing.go +++ b/testing.go @@ -20,6 +20,12 @@ var errAlreadyInProgress = regexp.MustCompile(`removal of container .* is alread // 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) { + defer func() { + if r := recover(); r != nil { + t.Skipf("Recovered from panic. Docker is not running. TestContainers can't perform is work without it") + } + }() + t.Helper() ctx := context.Background() provider, err := ProviderDocker.GetProvider()