Skip to content

Commit 42824ba

Browse files
authored
chore(format): fix suggestions detected by gopls modernize (#3208)
Apply gopls modernize tool with fix and format code.
1 parent cab584f commit 42824ba

17 files changed

+33
-55
lines changed

container.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"errors"
77
"fmt"
88
"io"
9+
"maps"
910
"os"
1011
"path/filepath"
1112
"strings"
@@ -457,9 +458,7 @@ func (c *ContainerRequest) BuildOptions() (build.ImageBuildOptions, error) {
457458
buildOptions.AuthConfigs = map[string]registry.AuthConfig{}
458459
}
459460

460-
for registry, authConfig := range authsFromDockerfile {
461-
buildOptions.AuthConfigs[registry] = authConfig
462-
}
461+
maps.Copy(buildOptions.AuthConfigs, authsFromDockerfile)
463462

464463
// make sure the first tag is the one defined in the ContainerRequest
465464
tag := fmt.Sprintf("%s:%s", c.GetRepo(), c.GetTag())

container_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ func TestShouldStartContainersInParallel(t *testing.T) {
510510
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute)
511511
t.Cleanup(cancel)
512512

513-
for i := 0; i < 3; i++ {
513+
for i := range 3 {
514514
i := i
515515
t.Run(fmt.Sprintf("iteration_%d", i), func(t *testing.T) {
516516
t.Parallel()

docker.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,13 +1062,7 @@ func (p *DockerProvider) CreateContainer(ctx context.Context, req ContainerReque
10621062
// as container won't be attached to it automatically
10631063
// in case of Podman the bridge network is called 'podman' as 'bridge' would conflict
10641064
if defaultNetwork != p.defaultBridgeNetworkName {
1065-
isAttached := false
1066-
for _, net := range req.Networks {
1067-
if net == defaultNetwork {
1068-
isAttached = true
1069-
break
1070-
}
1071-
}
1065+
isAttached := slices.Contains(req.Networks, defaultNetwork)
10721066

10731067
if !isAttached {
10741068
req.Networks = append(req.Networks, defaultNetwork)

docker_client_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func TestGetDockerInfo(t *testing.T) {
2828
wg := sync.WaitGroup{}
2929
wg.Add(count)
3030

31-
for i := 0; i < count; i++ {
31+
for range count {
3232
go func() {
3333
defer wg.Done()
3434
info, err := c.Info(ctx)

from_dockerfile_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func TestBuildImageFromDockerfile_NoTag(t *testing.T) {
136136

137137
func TestBuildImageFromDockerfile_Target(t *testing.T) {
138138
// there are three targets: target0, target1 and target2.
139-
for i := 0; i < 3; i++ {
139+
for i := range 3 {
140140
ctx := context.Background()
141141
c, err := GenericContainer(ctx, GenericContainerRequest{
142142
ContainerRequest: ContainerRequest{

generic.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"errors"
66
"fmt"
7+
"maps"
78
"strings"
89
"sync"
910

@@ -113,9 +114,7 @@ func GenericLabels() map[string]string {
113114

114115
// AddGenericLabels adds the generic labels to target.
115116
func AddGenericLabels(target map[string]string) {
116-
for k, v := range GenericLabels() {
117-
target[k] = v
118-
}
117+
maps.Copy(target, GenericLabels())
119118
}
120119

121120
// Run is a convenience function that creates a new container and starts it.

generic_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func TestGenericContainerShouldReturnRefOnError(t *testing.T) {
128128
func TestGenericReusableContainerInSubprocess(t *testing.T) {
129129
wg := sync.WaitGroup{}
130130
wg.Add(10)
131-
for i := 0; i < 10; i++ {
131+
for range 10 {
132132
go func() {
133133
defer wg.Done()
134134

internal/core/labels.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package core
33
import (
44
"errors"
55
"fmt"
6+
"maps"
67
"strings"
78

89
"github.com/testcontainers/testcontainers-go/internal"
@@ -51,9 +52,7 @@ func DefaultLabels(sessionID string) map[string]string {
5152

5253
// AddDefaultLabels adds the default labels for sessionID to target.
5354
func AddDefaultLabels(sessionID string, target map[string]string) {
54-
for k, v := range DefaultLabels(sessionID) {
55-
target[k] = v
56-
}
55+
maps.Copy(target, DefaultLabels(sessionID))
5756
}
5857

5958
// MergeCustomLabels sets labels from src to dst.

lifecycle.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ func combineContainerHooks(defaultHooks, userDefinedHooks []ContainerLifecycleHo
559559
hooksType := reflect.TypeOf(hooks)
560560
for _, defaultHook := range defaultHooks {
561561
defaultVal := reflect.ValueOf(defaultHook)
562-
for i := 0; i < hooksType.NumField(); i++ {
562+
for i := range hooksType.NumField() {
563563
if strings.HasPrefix(hooksType.Field(i).Name, "Pre") {
564564
field := hooksVal.Field(i)
565565
field.Set(reflect.AppendSlice(field, defaultVal.Field(i)))
@@ -572,7 +572,7 @@ func combineContainerHooks(defaultHooks, userDefinedHooks []ContainerLifecycleHo
572572
// post-hooks will be the first ones to be executed.
573573
for _, userDefinedHook := range userDefinedHooks {
574574
userVal := reflect.ValueOf(userDefinedHook)
575-
for i := 0; i < hooksType.NumField(); i++ {
575+
for i := range hooksType.NumField() {
576576
field := hooksVal.Field(i)
577577
field.Set(reflect.AppendSlice(field, userVal.Field(i)))
578578
}
@@ -581,7 +581,7 @@ func combineContainerHooks(defaultHooks, userDefinedHooks []ContainerLifecycleHo
581581
// Finally, append the default post-hooks.
582582
for _, defaultHook := range defaultHooks {
583583
defaultVal := reflect.ValueOf(defaultHook)
584-
for i := 0; i < hooksType.NumField(); i++ {
584+
for i := range hooksType.NumField() {
585585
if strings.HasPrefix(hooksType.Field(i).Name, "Post") {
586586
field := hooksVal.Field(i)
587587
field.Set(reflect.AppendSlice(field, defaultVal.Field(i)))

lifecycle_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ func TestCombineLifecycleHooks(t *testing.T) {
749749
// - pre-X hooks: first default (2*2), then user-defined (3*2)
750750
// - post-X hooks: first user-defined (3*2), then default (2*2)
751751

752-
for i := 0; i < 5; i++ {
752+
for i := range 5 {
753753
var hookType string
754754
// this is the particular order of execution for the hooks
755755
switch i {
@@ -1010,13 +1010,13 @@ func Test_combineContainerHooks(t *testing.T) {
10101010
gotVal := reflect.ValueOf(got)
10111011
gotType := reflect.TypeOf(got)
10121012
expectedVal := reflect.ValueOf(expects)
1013-
for i := 0; i < gotVal.NumField(); i++ {
1013+
for i := range gotVal.NumField() {
10141014
fieldName := gotType.Field(i).Name
10151015
gotField := gotVal.Field(i)
10161016
expectedField := expectedVal.Field(i)
10171017
require.Equalf(t, expectedField.Len(), 2, "field %q not setup len expected %d got %d", fieldName, 2, expectedField.Len()) //nolint:testifylint // False positive.
10181018
require.Equalf(t, expectedField.Len(), gotField.Len(), "field %q len expected %d got %d", fieldName, gotField.Len(), expectedField.Len())
1019-
for j := 0; j < gotField.Len(); j++ {
1019+
for j := range gotField.Len() {
10201020
gotIndex := gotField.Index(j)
10211021
expectedIndex := expectedField.Index(j)
10221022
var gotID string

0 commit comments

Comments
 (0)