Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ linters:
- testifylint
- thelper
- usestdlibvars
- usetesting
exclusions:
presets:
- comments
Expand Down Expand Up @@ -81,6 +82,10 @@ linters:
- float-compare
- go-require
enable-all: true
usetesting:
# Enable/disable `os.Setenv()` detections.
# Default: true
os-setenv: false
output:
formats:
text:
Expand Down
12 changes: 6 additions & 6 deletions container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ func Test_BuildImageWithContexts(t *testing.T) {
testCase := testCase
t.Run(testCase.Name, func(t *testing.T) {
t.Parallel()
ctx := context.Background()
ctx := t.Context()
a, err := testCase.ContextArchive()
require.NoError(t, err)

Expand Down Expand Up @@ -316,7 +316,7 @@ func TestCustomLabelsImage(t *testing.T) {
myLabelValue = "my-label-value"
)

ctx := context.Background()
ctx := t.Context()

ctr, err := testcontainers.Run(ctx, "alpine:latest", testcontainers.WithLabels(map[string]string{myLabelName: myLabelValue}))
testcontainers.CleanupContainer(t, ctr)
Expand All @@ -335,7 +335,7 @@ func TestCustomLabelsBuildOptionsModifier(t *testing.T) {
myBuildOptionValue = "my-bo-label-value"
)

ctx := context.Background()
ctx := t.Context()

ctr, err := testcontainers.Run(
ctx, "",
Expand All @@ -360,7 +360,7 @@ func TestCustomLabelsBuildOptionsModifier(t *testing.T) {
}

func Test_GetLogsFromFailedContainer(t *testing.T) {
ctx := context.Background()
ctx := t.Context()
// directDockerHubReference {
c, err := testcontainers.Run(
ctx, "alpine",
Expand Down Expand Up @@ -461,7 +461,7 @@ func TestImageSubstitutors(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
ctx := context.Background()
ctx := t.Context()
ctr, err := testcontainers.Run(ctx, test.image, testcontainers.WithImageSubstitutors(test.substitutors...))
testcontainers.CleanupContainer(t, ctr)
if test.expectedError != nil {
Expand All @@ -476,7 +476,7 @@ func TestImageSubstitutors(t *testing.T) {
}

func TestShouldStartContainersInParallel(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute)
ctx, cancel := context.WithTimeout(t.Context(), 1*time.Minute)
t.Cleanup(cancel)

for i := range 3 {
Expand Down
20 changes: 10 additions & 10 deletions docker_auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func TestDockerImageAuth(t *testing.T) {
username, password := "gopher", "secret"
creds := setAuthConfig(t, exampleAuth, username, password)

registry, cfg, err := DockerImageAuth(context.Background(), exampleAuth+"/my/image:latest")
registry, cfg, err := DockerImageAuth(t.Context(), exampleAuth+"/my/image:latest")
require.NoError(t, err)
require.Equal(t, exampleAuth, registry)
require.Equal(t, username, cfg.Username)
Expand All @@ -115,7 +115,7 @@ func TestDockerImageAuth(t *testing.T) {
imagePath := "/my/image:latest"
base64 := setAuthConfig(t, exampleAuth, "gopher", "secret")

registry, cfg, err := DockerImageAuth(context.Background(), imageReg+imagePath)
registry, cfg, err := DockerImageAuth(t.Context(), imageReg+imagePath)
require.NoError(t, err)
require.Equal(t, imageReg, registry)
require.Equal(t, "gopher", cfg.Username)
Expand All @@ -130,7 +130,7 @@ func TestDockerImageAuth(t *testing.T) {

setAuthConfig(t, invalidRegistryURL, "gopher", "secret")

registry, cfg, err := DockerImageAuth(context.Background(), imageReg+imagePath)
registry, cfg, err := DockerImageAuth(t.Context(), imageReg+imagePath)
require.ErrorIs(t, err, dockercfg.ErrCredentialsNotFound)
require.Empty(t, cfg)
require.Equal(t, imageReg, registry)
Expand All @@ -150,15 +150,15 @@ func TestDockerImageAuth(t *testing.T) {

setAuthConfig(t, "example-auth.com", "gopher", "secret")

registry, cfg, err := DockerImageAuth(context.Background(), imageReg+imagePath)
registry, cfg, err := DockerImageAuth(t.Context(), imageReg+imagePath)
require.ErrorIs(t, err, dockercfg.ErrCredentialsNotFound)
require.Empty(t, cfg)
require.Equal(t, imageReg, registry)
})
}

func TestBuildContainerFromDockerfile(t *testing.T) {
ctx := context.Background()
ctx := t.Context()

redisC, err := Run(ctx, "",
WithDockerfile(FromDockerfile{
Expand All @@ -175,7 +175,7 @@ func TestBuildContainerFromDockerfile(t *testing.T) {
// removeImageFromLocalCache removes the image from the local cache
func removeImageFromLocalCache(t *testing.T, img string) {
t.Helper()
ctx := context.Background()
ctx := t.Context()

testcontainersClient, err := NewDockerClientWithOpts(ctx, client.WithVersion(daemonMaxVersion))
if err != nil {
Expand All @@ -198,7 +198,7 @@ func TestBuildContainerFromDockerfileWithDockerAuthConfig(t *testing.T) {
// using the same credentials as in the Docker Registry
setAuthConfig(t, registryHost, "testuser", "testpassword")

ctx := context.Background()
ctx := t.Context()

redisC, err := Run(ctx, "",
WithDockerfile(FromDockerfile{
Expand All @@ -223,7 +223,7 @@ func TestBuildContainerFromDockerfileShouldFailWithWrongDockerAuthConfig(t *test
// using different credentials than in the Docker Registry
setAuthConfig(t, registryHost, "foo", "bar")

ctx := context.Background()
ctx := t.Context()

redisC, err := Run(ctx, "",
WithDockerfile(FromDockerfile{
Expand All @@ -247,7 +247,7 @@ func TestCreateContainerFromPrivateRegistry(t *testing.T) {
// using the same credentials as in the Docker Registry
setAuthConfig(t, registryHost, "testuser", "testpassword")

ctx := context.Background()
ctx := t.Context()

redisContainer, err := Run(ctx, registryHost+"/redis:5.0-alpine", WithAlwaysPull(), WithExposedPorts("6379/tcp"), WithWaitStrategy(wait.ForLog("Ready to accept connections")))
CleanupContainer(t, redisContainer)
Expand All @@ -256,7 +256,7 @@ func TestCreateContainerFromPrivateRegistry(t *testing.T) {

func prepareLocalRegistryWithAuth(t *testing.T) string {
t.Helper()
ctx := context.Background()
ctx := t.Context()
wd, err := os.Getwd()
require.NoError(t, err)
// copyDirectoryToContainer {
Expand Down
5 changes: 2 additions & 3 deletions docker_client_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package testcontainers

import (
"context"
"sync"
"testing"

Expand All @@ -10,7 +9,7 @@ import (

func TestGetDockerInfo(t *testing.T) {
t.Run("works", func(t *testing.T) {
ctx := context.Background()
ctx := t.Context()
c, err := NewDockerClientWithOpts(ctx)
require.NoError(t, err)

Expand All @@ -20,7 +19,7 @@ func TestGetDockerInfo(t *testing.T) {
})

t.Run("is goroutine safe", func(t *testing.T) {
ctx := context.Background()
ctx := t.Context()
c, err := NewDockerClientWithOpts(ctx)
require.NoError(t, err)

Expand Down
7 changes: 3 additions & 4 deletions docker_exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package testcontainers

import (
"bytes"
"context"
"io"
"testing"

Expand Down Expand Up @@ -46,7 +45,7 @@ func TestExecWithOptions(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ctx := context.Background()
ctx := t.Context()

ctr, err := Run(ctx, nginxAlpineImage)
CleanupContainer(t, ctr)
Expand All @@ -72,7 +71,7 @@ func TestExecWithOptions(t *testing.T) {
}

func TestExecWithMultiplexedResponse(t *testing.T) {
ctx := context.Background()
ctx := t.Context()

ctr, err := Run(ctx, nginxAlpineImage)
CleanupContainer(t, ctr)
Expand All @@ -93,7 +92,7 @@ func TestExecWithMultiplexedResponse(t *testing.T) {
}

func TestExecWithNonMultiplexedResponse(t *testing.T) {
ctx := context.Background()
ctx := t.Context()

ctr, err := Run(ctx, nginxAlpineImage)
CleanupContainer(t, ctr)
Expand Down
10 changes: 5 additions & 5 deletions docker_files_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
const testBashImage string = "bash:5.2.26"

func TestCopyFileToContainer(t *testing.T) {
ctx, cnl := context.WithTimeout(context.Background(), 30*time.Second)
ctx, cnl := context.WithTimeout(t.Context(), 30*time.Second)
defer cnl()

// copyFileOnCreate {
Expand All @@ -42,7 +42,7 @@ func TestCopyFileToContainer(t *testing.T) {
}

func TestCopyFileToRunningContainer(t *testing.T) {
ctx, cnl := context.WithTimeout(context.Background(), 30*time.Second)
ctx, cnl := context.WithTimeout(t.Context(), 30*time.Second)
defer cnl()

// Not using the assertations here to avoid leaking the library into the example
Expand Down Expand Up @@ -74,7 +74,7 @@ func TestCopyFileToRunningContainer(t *testing.T) {
}

func TestCopyDirectoryToContainer(t *testing.T) {
ctx, cnl := context.WithTimeout(context.Background(), 30*time.Second)
ctx, cnl := context.WithTimeout(t.Context(), 30*time.Second)
defer cnl()

// Not using the assertations here to avoid leaking the library into the example
Expand All @@ -100,7 +100,7 @@ func TestCopyDirectoryToContainer(t *testing.T) {
}

func TestCopyDirectoryToRunningContainerAsFile(t *testing.T) {
ctx, cnl := context.WithTimeout(context.Background(), 30*time.Second)
ctx, cnl := context.WithTimeout(t.Context(), 30*time.Second)
defer cnl()

// copyDirectoryToRunningContainerAsFile {
Expand Down Expand Up @@ -131,7 +131,7 @@ func TestCopyDirectoryToRunningContainerAsFile(t *testing.T) {
}

func TestCopyDirectoryToRunningContainerAsDir(t *testing.T) {
ctx, cnl := context.WithTimeout(context.Background(), 30*time.Second)
ctx, cnl := context.WithTimeout(t.Context(), 30*time.Second)
defer cnl()

// Not using the assertations here to avoid leaking the library into the example
Expand Down
Loading
Loading