Skip to content

Commit b74984d

Browse files
authored
golangci-lint: enable thelper linter (#2834)
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
1 parent 5e988ff commit b74984d

26 files changed

+51
-13
lines changed

.golangci.yml

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
linters:
22
enable:
3+
- errcheck
34
- errorlint
45
- gci
56
- gocritic
67
- gofumpt
78
- misspell
9+
- nolintlint
810
- nonamedreturns
911
- testifylint
10-
- errcheck
11-
- nolintlint
12+
- thelper
1213

1314
linters-settings:
1415
errorlint:
@@ -30,16 +31,6 @@ linters-settings:
3031
disable:
3132
- float-compare
3233
- go-require
33-
enable:
34-
- bool-compare
35-
- compares
36-
- empty
37-
- error-is-as
38-
- error-nil
39-
- expected-actual
40-
- len
41-
- require-error
42-
- suite-dont-use-pkg
43-
- suite-extra-assert-call
34+
enable-all: true
4435
run:
4536
timeout: 5m

docker_auth_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ func TestBuildContainerFromDockerfile(t *testing.T) {
170170

171171
// removeImageFromLocalCache removes the image from the local cache
172172
func removeImageFromLocalCache(t *testing.T, img string) {
173+
t.Helper()
173174
ctx := context.Background()
174175

175176
testcontainersClient, err := NewDockerClientWithOpts(ctx, client.WithVersion(daemonMaxVersion))
@@ -263,6 +264,7 @@ func TestCreateContainerFromPrivateRegistry(t *testing.T) {
263264
}
264265

265266
func prepareLocalRegistryWithAuth(t *testing.T) string {
267+
t.Helper()
266268
ctx := context.Background()
267269
wd, err := os.Getwd()
268270
require.NoError(t, err)
@@ -359,6 +361,7 @@ func setAuthConfig(t *testing.T, host, username, password string) string {
359361
// which can be used to connect to the local registry.
360362
// This avoids the issues with localhost on WSL.
361363
func localAddress(t *testing.T) string {
364+
t.Helper()
362365
if os.Getenv("WSL_DISTRO_NAME") == "" {
363366
return "localhost"
364367
}

docker_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,6 +1345,7 @@ func TestContainerInspect_RawInspectIsCleanedOnStop(t *testing.T) {
13451345
}
13461346

13471347
func readHostname(tb testing.TB, containerId string) string {
1348+
tb.Helper()
13481349
containerClient, err := NewDockerClientWithOpts(context.Background())
13491350
if err != nil {
13501351
tb.Fatalf("Failed to create Docker client: %v", err)
@@ -1917,6 +1918,7 @@ func TestNetworkModeWithContainerReference(t *testing.T) {
19171918

19181919
// creates a temporary dir in which the files will be extracted. Then it will compare the bytes of each file in the source with the bytes from the copied-from-container file
19191920
func assertExtractedFiles(t *testing.T, ctx context.Context, container Container, hostFilePath string, containerFilePath string) {
1921+
t.Helper()
19201922
// create all copied files into a temporary dir
19211923
tmpDir := t.TempDir()
19221924

generic_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ func TestGenericReusableContainerInSubprocess(t *testing.T) {
164164
}
165165

166166
func createReuseContainerInSubprocess(t *testing.T) string {
167+
t.Helper()
167168
// force verbosity in subprocesses, so that the output is printed
168169
cmd := exec.Command(os.Args[0], "-test.run=TestHelperContainerStarterProcess", "-test.v=true")
169170
cmd.Env = append(os.Environ(), "GO_WANT_HELPER_PROCESS=1")

internal/config/config_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const (
1919
// unset environment variables to avoid side effects
2020
// execute this function before each test
2121
func resetTestEnv(t *testing.T) {
22+
t.Helper()
2223
t.Setenv("TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX", "")
2324
t.Setenv("TESTCONTAINERS_RYUK_DISABLED", "")
2425
t.Setenv("TESTCONTAINERS_RYUK_CONTAINER_PRIVILEGED", "")

internal/core/docker_host_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ func testCallbackCheckError(_ context.Context, _ string) error {
5050
}
5151

5252
func mockCallbackCheck(t *testing.T, fn func(_ context.Context, _ string) error) {
53+
t.Helper()
5354
oldCheck := dockerHostCheck
5455
dockerHostCheck = fn
5556
t.Cleanup(func() {
@@ -515,10 +516,12 @@ func createTmpDockerSocket(parent string) error {
515516
// setupDockerHostNotFound sets up the environment for the test case where the DOCKER_HOST environment variable is
516517
// already set (e.g. rootless docker) therefore we need to unset it before the test
517518
func setupDockerHostNotFound(t *testing.T) {
519+
t.Helper()
518520
t.Setenv("DOCKER_HOST", "")
519521
}
520522

521523
func setupDockerSocket(t *testing.T) string {
524+
t.Helper()
522525
t.Cleanup(func() {
523526
DockerSocketPath = originalDockerSocketPath
524527
DockerSocketPathWithSchema = originalDockerSocketPathWithSchema
@@ -536,6 +539,7 @@ func setupDockerSocket(t *testing.T) string {
536539
}
537540

538541
func setupDockerSocketNotFound(t *testing.T) {
542+
t.Helper()
539543
t.Cleanup(func() {
540544
DockerSocketPath = originalDockerSocketPath
541545
DockerSocketPathWithSchema = originalDockerSocketPathWithSchema
@@ -548,6 +552,7 @@ func setupDockerSocketNotFound(t *testing.T) {
548552
}
549553

550554
func setupTestcontainersProperties(t *testing.T, content string) {
555+
t.Helper()
551556
t.Cleanup(func() {
552557
// reset the properties file after the test
553558
config.Reset()

internal/core/docker_rootless_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ func TestRootlessDockerSocketPath(t *testing.T) {
184184
}
185185

186186
func setupRootlessNotFound(t *testing.T) {
187+
t.Helper()
187188
t.Cleanup(func() {
188189
baseRunDir = originalBaseRunDir
189190
os.Setenv("XDG_RUNTIME_DIR", originalXDGRuntimeDir)

modulegen/context_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
)
1212

1313
func getTestRootContext(t *testing.T) context.Context {
14+
t.Helper()
1415
current, err := os.Getwd()
1516
require.NoError(t, err)
1617
return context.New(filepath.Dir(current))

modulegen/main_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ func TestGenerateModule(t *testing.T) {
357357

358358
// assert content module file in the docs
359359
func assertModuleDocContent(t *testing.T, module context.TestcontainersModule, moduleDocFile string) {
360+
t.Helper()
360361
content, err := os.ReadFile(moduleDocFile)
361362
require.NoError(t, err)
362363

@@ -383,6 +384,7 @@ func assertModuleDocContent(t *testing.T, module context.TestcontainersModule, m
383384

384385
// assert content module test
385386
func assertExamplesTestContent(t *testing.T, module context.TestcontainersModule, examplesTestFile string) {
387+
t.Helper()
386388
content, err := os.ReadFile(examplesTestFile)
387389
require.NoError(t, err)
388390

@@ -402,6 +404,7 @@ func assertExamplesTestContent(t *testing.T, module context.TestcontainersModule
402404

403405
// assert content module test
404406
func assertModuleTestContent(t *testing.T, module context.TestcontainersModule, exampleTestFile string) {
407+
t.Helper()
405408
content, err := os.ReadFile(exampleTestFile)
406409
require.NoError(t, err)
407410

@@ -413,6 +416,7 @@ func assertModuleTestContent(t *testing.T, module context.TestcontainersModule,
413416

414417
// assert content module
415418
func assertModuleContent(t *testing.T, module context.TestcontainersModule, exampleFile string) {
419+
t.Helper()
416420
content, err := os.ReadFile(exampleFile)
417421
require.NoError(t, err)
418422

@@ -437,6 +441,7 @@ func assertModuleContent(t *testing.T, module context.TestcontainersModule, exam
437441

438442
// assert content GitHub workflow for the module
439443
func assertModuleGithubWorkflowContent(t *testing.T, moduleWorkflowFile string) {
444+
t.Helper()
440445
content, err := os.ReadFile(moduleWorkflowFile)
441446
require.NoError(t, err)
442447

@@ -454,6 +459,7 @@ func assertModuleGithubWorkflowContent(t *testing.T, moduleWorkflowFile string)
454459

455460
// assert content go.mod
456461
func assertGoModContent(t *testing.T, module context.TestcontainersModule, tcVersion string, goModFile string) {
462+
t.Helper()
457463
content, err := os.ReadFile(goModFile)
458464
require.NoError(t, err)
459465

@@ -465,6 +471,7 @@ func assertGoModContent(t *testing.T, module context.TestcontainersModule, tcVer
465471

466472
// assert content Makefile
467473
func assertMakefileContent(t *testing.T, module context.TestcontainersModule, makefile string) {
474+
t.Helper()
468475
content, err := os.ReadFile(makefile)
469476
require.NoError(t, err)
470477

@@ -474,6 +481,7 @@ func assertMakefileContent(t *testing.T, module context.TestcontainersModule, ma
474481

475482
// assert content in the nav items from mkdocs.yml
476483
func assertMkdocsNavItems(t *testing.T, module context.TestcontainersModule, originalConfig *mkdocs.Config, tmpCtx context.Context) {
484+
t.Helper()
477485
config, err := mkdocs.ReadConfig(tmpCtx.MkdocsConfigFile())
478486
require.NoError(t, err)
479487

modulegen/mkdocs_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ func TestNavItems(t *testing.T) {
8282
}
8383

8484
func copyInitialMkdocsConfig(t *testing.T, tmpCtx context.Context) error {
85+
t.Helper()
8586
ctx := getTestRootContext(t)
8687
return mkdocs.CopyConfig(ctx.MkdocsConfigFile(), tmpCtx.MkdocsConfigFile())
8788
}

0 commit comments

Comments
 (0)