diff --git a/indexer_test.go b/indexer_test.go index 525af82..82a0d0b 100644 --- a/indexer_test.go +++ b/indexer_test.go @@ -2,6 +2,8 @@ package indexer import ( "context" + "crypto/sha256" + "encoding/hex" "fmt" "os" "testing" @@ -18,6 +20,20 @@ import ( const record = false +func WithReuse(testPath string) testcontainers.CustomizeRequestOption { + return func(req *testcontainers.GenericContainerRequest) error { + h := sha256.New() + h.Write([]byte(testPath)) + hash := h.Sum(nil) + + req.Name = "wiremock-" + hex.EncodeToString(hash) + req.Reuse = true + + return nil + } +} + + func spinUpContainer(t *testing.T) string { t.Helper() @@ -29,8 +45,11 @@ func spinUpContainer(t *testing.T) string { } var opts []testcontainers.ContainerCustomizer - - opts = append(opts, testcontainers_wiremock.WithImage("wiremock/wiremock:3.12.1")) + opts = append( + opts, + testcontainers_wiremock.WithImage("wiremock/wiremock:3.12.1"), + WithReuse(absolutePath), + ) if record { opts = append(opts, testcontainers.WithHostConfigModifier(func(hostConfig *container.HostConfig) { @@ -51,9 +70,8 @@ func spinUpContainer(t *testing.T) string { } } - container, err := testcontainers_wiremock.RunContainerAndStopOnCleanup( + container, err := testcontainers_wiremock.RunContainer( ctx, - t, opts..., )