Skip to content

Commit 8324faf

Browse files
committed
chore: enable ustesting linter
Signed-off-by: Matthieu MOREL <[email protected]>
1 parent 7eb93bb commit 8324faf

File tree

153 files changed

+826
-904
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

153 files changed

+826
-904
lines changed

.golangci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ linters:
2020
- testifylint
2121
- thelper
2222
- usestdlibvars
23+
- usetesting
2324
exclusions:
2425
presets:
2526
- comments
@@ -81,6 +82,10 @@ linters:
8182
- float-compare
8283
- go-require
8384
enable-all: true
85+
usetesting:
86+
# Enable/disable `os.Setenv()` detections.
87+
# Default: true
88+
os-setenv: false
8489
output:
8590
formats:
8691
text:

container_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ func Test_BuildImageWithContexts(t *testing.T) {
285285
testCase := testCase
286286
t.Run(testCase.Name, func(t *testing.T) {
287287
t.Parallel()
288-
ctx := context.Background()
288+
ctx := t.Context()
289289
a, err := testCase.ContextArchive()
290290
require.NoError(t, err)
291291

@@ -316,7 +316,7 @@ func TestCustomLabelsImage(t *testing.T) {
316316
myLabelValue = "my-label-value"
317317
)
318318

319-
ctx := context.Background()
319+
ctx := t.Context()
320320

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

338-
ctx := context.Background()
338+
ctx := t.Context()
339339

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

362362
func Test_GetLogsFromFailedContainer(t *testing.T) {
363-
ctx := context.Background()
363+
ctx := t.Context()
364364
// directDockerHubReference {
365365
c, err := testcontainers.Run(
366366
ctx, "alpine",
@@ -461,7 +461,7 @@ func TestImageSubstitutors(t *testing.T) {
461461

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

478478
func TestShouldStartContainersInParallel(t *testing.T) {
479-
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute)
479+
ctx, cancel := context.WithTimeout(t.Context(), 1*time.Minute)
480480
t.Cleanup(cancel)
481481

482482
for i := range 3 {

docker_auth_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func TestDockerImageAuth(t *testing.T) {
102102
username, password := "gopher", "secret"
103103
creds := setAuthConfig(t, exampleAuth, username, password)
104104

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

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

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

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

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

153-
registry, cfg, err := DockerImageAuth(context.Background(), imageReg+imagePath)
153+
registry, cfg, err := DockerImageAuth(t.Context(), imageReg+imagePath)
154154
require.ErrorIs(t, err, dockercfg.ErrCredentialsNotFound)
155155
require.Empty(t, cfg)
156156
require.Equal(t, imageReg, registry)
157157
})
158158
}
159159

160160
func TestBuildContainerFromDockerfile(t *testing.T) {
161-
ctx := context.Background()
161+
ctx := t.Context()
162162

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

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

201-
ctx := context.Background()
201+
ctx := t.Context()
202202

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

226-
ctx := context.Background()
226+
ctx := t.Context()
227227

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

250-
ctx := context.Background()
250+
ctx := t.Context()
251251

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

257257
func prepareLocalRegistryWithAuth(t *testing.T) string {
258258
t.Helper()
259-
ctx := context.Background()
259+
ctx := t.Context()
260260
wd, err := os.Getwd()
261261
require.NoError(t, err)
262262
// copyDirectoryToContainer {

docker_client_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package testcontainers
22

33
import (
4-
"context"
54
"sync"
65
"testing"
76

@@ -10,7 +9,7 @@ import (
109

1110
func TestGetDockerInfo(t *testing.T) {
1211
t.Run("works", func(t *testing.T) {
13-
ctx := context.Background()
12+
ctx := t.Context()
1413
c, err := NewDockerClientWithOpts(ctx)
1514
require.NoError(t, err)
1615

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

2221
t.Run("is goroutine safe", func(t *testing.T) {
23-
ctx := context.Background()
22+
ctx := t.Context()
2423
c, err := NewDockerClientWithOpts(ctx)
2524
require.NoError(t, err)
2625

docker_exec_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package testcontainers
22

33
import (
44
"bytes"
5-
"context"
65
"io"
76
"testing"
87

@@ -46,7 +45,7 @@ func TestExecWithOptions(t *testing.T) {
4645
}
4746
for _, tt := range tests {
4847
t.Run(tt.name, func(t *testing.T) {
49-
ctx := context.Background()
48+
ctx := t.Context()
5049

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

7473
func TestExecWithMultiplexedResponse(t *testing.T) {
75-
ctx := context.Background()
74+
ctx := t.Context()
7675

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

9594
func TestExecWithNonMultiplexedResponse(t *testing.T) {
96-
ctx := context.Background()
95+
ctx := t.Context()
9796

9897
ctr, err := Run(ctx, nginxAlpineImage)
9998
CleanupContainer(t, ctr)

docker_files_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
const testBashImage string = "bash:5.2.26"
1717

1818
func TestCopyFileToContainer(t *testing.T) {
19-
ctx, cnl := context.WithTimeout(context.Background(), 30*time.Second)
19+
ctx, cnl := context.WithTimeout(t.Context(), 30*time.Second)
2020
defer cnl()
2121

2222
// copyFileOnCreate {
@@ -42,7 +42,7 @@ func TestCopyFileToContainer(t *testing.T) {
4242
}
4343

4444
func TestCopyFileToRunningContainer(t *testing.T) {
45-
ctx, cnl := context.WithTimeout(context.Background(), 30*time.Second)
45+
ctx, cnl := context.WithTimeout(t.Context(), 30*time.Second)
4646
defer cnl()
4747

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

7676
func TestCopyDirectoryToContainer(t *testing.T) {
77-
ctx, cnl := context.WithTimeout(context.Background(), 30*time.Second)
77+
ctx, cnl := context.WithTimeout(t.Context(), 30*time.Second)
7878
defer cnl()
7979

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

102102
func TestCopyDirectoryToRunningContainerAsFile(t *testing.T) {
103-
ctx, cnl := context.WithTimeout(context.Background(), 30*time.Second)
103+
ctx, cnl := context.WithTimeout(t.Context(), 30*time.Second)
104104
defer cnl()
105105

106106
// copyDirectoryToRunningContainerAsFile {
@@ -131,7 +131,7 @@ func TestCopyDirectoryToRunningContainerAsFile(t *testing.T) {
131131
}
132132

133133
func TestCopyDirectoryToRunningContainerAsDir(t *testing.T) {
134-
ctx, cnl := context.WithTimeout(context.Background(), 30*time.Second)
134+
ctx, cnl := context.WithTimeout(t.Context(), 30*time.Second)
135135
defer cnl()
136136

137137
// Not using the assertations here to avoid leaking the library into the example

0 commit comments

Comments
 (0)