testutil: use lazyregexp to compile regexes on first use

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2024-07-15 16:29:43 +02:00
parent b5d90d746b
commit 72ebf2c309

View File

@@ -2,7 +2,6 @@ package environment // import "github.com/docker/docker/testutil/environment"
import (
"context"
"regexp"
"strings"
"testing"
@@ -14,6 +13,7 @@ import (
"github.com/docker/docker/api/types/volume"
"github.com/docker/docker/client"
"github.com/docker/docker/errdefs"
"github.com/docker/docker/internal/lazyregexp"
"go.opentelemetry.io/otel"
"gotest.tools/v3/assert"
)
@@ -63,7 +63,8 @@ func getPausedContainers(ctx context.Context, t testing.TB, client client.Contai
return containers
}
var alreadyExists = regexp.MustCompile(`Error response from daemon: removal of container (\w+) is already in progress`)
// FIXME(thaJeztah): can we rewrite this check to not do string-matching, and instead detect error-type?
var alreadyExists = lazyregexp.New(`Error response from daemon: removal of container (\w+) is already in progress`)
func deleteAllContainers(ctx context.Context, t testing.TB, apiclient client.ContainerAPIClient, protectedContainers map[string]struct{}) {
t.Helper()