Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo Chacin <pablochacin@gmail.com>
  • Loading branch information
pablochacin committed Oct 26, 2023
1 parent cd568f1 commit 152e720
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions modules/k6/k6.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
"github.com/docker/docker/api/types/mount"

"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/internal/testcontainersdocker"
"github.com/testcontainers/testcontainers-go/internal/testcontainerssession"
"github.com/testcontainers/testcontainers-go/wait"
)

Expand Down Expand Up @@ -55,18 +53,18 @@ func SetEnvVar(variable string, value string) testcontainers.CustomizeRequestOpt
}

// WithCache sets a volume as a cache for building the k6 binary
// If a volume name is provided in the TC_K6_BUILD_CACHE, this volume is used.
// If no value is provided, a volume is created and removed when the test session ends.
// If a volume name is provided in the TC_K6_BUILD_CACHE, this volume is used and it will
// persist across test sessions.
// If no value is provided, a volume is created and automatically deleted when the test session ends.
func WithCache() testcontainers.CustomizeRequestOption {
var volOptions *mount.VolumeOptions

cacheVol := os.Getenv("TC_K6_BUILD_CACHE")
// if no volume is provided, create one and ensure add labels for garbage collection
if cacheVol == "" {
sessionID := testcontainerssession.SessionID()
cacheVol = fmt.Sprintf("k6-cache-%s", sessionID)
cacheVol = fmt.Sprintf("k6-cache-%s", testcontainers.SessionID())
volOptions = &mount.VolumeOptions{
Labels: testcontainersdocker.DefaultLabels(sessionID),
Labels: testcontainers.GenericLabels(),
}
}

Expand Down

0 comments on commit 152e720

Please sign in to comment.