Skip to content

Commit

Permalink
Merge pull request moby#48856 from thaJeztah/copyloopvar
Browse files Browse the repository at this point in the history
update go:build tags to use go1.22, and enable copyloopvar linter
  • Loading branch information
thaJeztah authored Nov 12, 2024
2 parents ae21b3c + 7d89d83 commit a95a678
Show file tree
Hide file tree
Showing 129 changed files with 224 additions and 371 deletions.
11 changes: 6 additions & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
linters:
enable:
- copyloopvar # Detects places where loop variables are copied.
- depguard
- dupword # Checks for duplicate words in the source code.
- dupword # Detects duplicate words.
- goimports
- gosec
- gosec # Detects security problems.
- gosimple
- govet
- forbidigo
- importas
- ineffassign
- misspell
- revive
- misspell # Detects commonly misspelled English words in comments.
- revive # Metalinter; drop-in replacement for golint.
- staticcheck
- typecheck
- unconvert
- unconvert # Detects unnecessary type conversions.
- unused

disable:
Expand Down
1 change: 0 additions & 1 deletion api/server/httputils/form_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ func TestUint32Value(t *testing.T) {
},
}
for _, tc := range tests {
tc := tc
t.Run(tc.value, func(t *testing.T) {
r, _ := http.NewRequest(http.MethodPost, "", nil)
r.Form = url.Values{}
Expand Down
1 change: 0 additions & 1 deletion api/server/middleware/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ func TestNewVersionMiddlewareValidation(t *testing.T) {
}

for _, tc := range tests {
tc := tc
t.Run(tc.doc, func(t *testing.T) {
_, err := NewVersionMiddleware("1.2.3", tc.defaultVersion, tc.minVersion)
if tc.expectedErr == "" {
Expand Down
2 changes: 1 addition & 1 deletion api/server/router/grpc/grpc.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// FIXME(thaJeztah): remove once we are a module; the go:build directive prevents go from downgrading language version to go1.16:
//go:build go1.21
//go:build go1.22

package grpc // import "github.com/docker/docker/api/server/router/grpc"

Expand Down
2 changes: 1 addition & 1 deletion api/server/router/system/system.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// FIXME(thaJeztah): remove once we are a module; the go:build directive prevents go from downgrading language version to go1.16:
//go:build go1.21
//go:build go1.22

package system // import "github.com/docker/docker/api/server/router/system"

Expand Down
1 change: 0 additions & 1 deletion api/types/container/hostconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ func TestValidateRestartPolicy(t *testing.T) {
}

for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
err := ValidateRestartPolicy(tc.input)
if tc.expectedErr == "" {
Expand Down
1 change: 0 additions & 1 deletion api/types/filters/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,6 @@ func TestGetBoolOrDefault(t *testing.T) {
expectedValue: false,
},
} {
tc := tc
t.Run(tc.name, func(t *testing.T) {
a := NewArgs()

Expand Down
10 changes: 4 additions & 6 deletions api/types/network/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (stub subnetStub) Contains(addr net.IP) bool {
}

func TestEndpointIPAMConfigWithOutOfRangeAddrs(t *testing.T) {
testcases := []struct {
tests := []struct {
name string
ipamConfig *EndpointIPAMConfig
v4Subnets []NetworkSubnet
Expand Down Expand Up @@ -80,8 +80,7 @@ func TestEndpointIPAMConfigWithOutOfRangeAddrs(t *testing.T) {
},
}

for _, tc := range testcases {
tc := tc
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()

Expand All @@ -105,7 +104,7 @@ func TestEndpointIPAMConfigWithOutOfRangeAddrs(t *testing.T) {
}

func TestEndpointIPAMConfigWithInvalidConfig(t *testing.T) {
testcases := []struct {
tests := []struct {
name string
ipamConfig *EndpointIPAMConfig
expectedErrors []string
Expand Down Expand Up @@ -162,8 +161,7 @@ func TestEndpointIPAMConfigWithInvalidConfig(t *testing.T) {
},
}

for _, tc := range testcases {
tc := tc
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()

Expand Down
5 changes: 2 additions & 3 deletions api/types/network/ipam_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

func TestNetworkWithInvalidIPAM(t *testing.T) {
testcases := []struct {
tests := []struct {
name string
ipam IPAM
ipv6 bool
Expand Down Expand Up @@ -123,8 +123,7 @@ func TestNetworkWithInvalidIPAM(t *testing.T) {
},
}

for _, tc := range testcases {
tc := tc
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()

Expand Down
2 changes: 1 addition & 1 deletion builder/builder-next/adapters/containerimage/pull.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// FIXME(thaJeztah): remove once we are a module; the go:build directive prevents go from downgrading language version to go1.16:
//go:build go1.21
//go:build go1.22

package containerimage

Expand Down
1 change: 0 additions & 1 deletion builder/remotecontext/git/gitutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ func TestParseRemoteURL(t *testing.T) {
}

for _, tc := range tests {
tc := tc
t.Run(tc.doc, func(t *testing.T) {
repo, err := parseRemoteURL(tc.url)
assert.NilError(t, err)
Expand Down
3 changes: 0 additions & 3 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ func TestNewClientWithOpsFromEnv(t *testing.T) {

env.PatchAll(t, nil)
for _, tc := range testcases {
tc := tc
t.Run(tc.doc, func(t *testing.T) {
env.PatchAll(t, tc.envs)
client, err := NewClientWithOpts(FromEnv)
Expand Down Expand Up @@ -323,7 +322,6 @@ func TestNegotiateAPIVersion(t *testing.T) {
}

for _, tc := range tests {
tc := tc
t.Run(tc.doc, func(t *testing.T) {
opts := make([]Opt, 0)
if tc.clientVersion != "" {
Expand Down Expand Up @@ -478,7 +476,6 @@ func TestClientRedirect(t *testing.T) {
}

for _, tc := range tests {
tc := tc
t.Run(tc.httpMethod, func(t *testing.T) {
req, err := http.NewRequest(tc.httpMethod, "/redirectme", nil)
assert.Check(t, err)
Expand Down
1 change: 0 additions & 1 deletion client/image_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ func TestImageListWithSharedSize(t *testing.T) {
{name: "set after 1.42, if requested", version: "1.42", options: image.ListOptions{SharedSize: true}, sharedSize: "1"},
{name: "unset before 1.42, even if requested", version: "1.41", options: image.ListOptions{SharedSize: true}},
} {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
var query url.Values
Expand Down
1 change: 0 additions & 1 deletion client/image_push_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ func TestImagePushWithoutErrors(t *testing.T) {
},
}
for _, tc := range testCases {
tc := tc
t.Run(fmt.Sprintf("%s,all-tags=%t", tc.reference, tc.all), func(t *testing.T) {
client := &Client{
client: newMockClient(func(req *http.Request) (*http.Response, error) {
Expand Down
2 changes: 0 additions & 2 deletions client/image_tag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ func TestImageTagInvalidSourceImageName(t *testing.T) {

invalidRepos := []string{"fo$z$", "Foo@3cc", "Foo$3", "Foo*3", "Fo^3", "Foo!3", "F)xcz(", "fo%asd", "aa/asdf$$^/aa"}
for _, repo := range invalidRepos {
repo := repo
t.Run("invalidRepo/"+repo, func(t *testing.T) {
t.Parallel()
err := client.ImageTag(ctx, "busybox", repo)
Expand All @@ -58,7 +57,6 @@ func TestImageTagInvalidSourceImageName(t *testing.T) {
longTag := testutil.GenerateRandomAlphaOnlyString(121)
invalidTags := []string{"repo:fo$z$", "repo:Foo@3cc", "repo:Foo$3", "repo:Foo*3", "repo:Fo^3", "repo:Foo!3", "repo:%goodbye", "repo:#hashtagit", "repo:F)xcz(", "repo:-foo", "repo:..", longTag}
for _, repotag := range invalidTags {
repotag := repotag
t.Run("invalidTag/"+repotag, func(t *testing.T) {
t.Parallel()
err := client.ImageTag(ctx, "busybox", repotag)
Expand Down
1 change: 0 additions & 1 deletion client/ping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ func TestPingHeadFallback(t *testing.T) {
}

for _, tc := range tests {
tc := tc
t.Run(http.StatusText(tc.status), func(t *testing.T) {
var reqs []string
client := &Client{
Expand Down
1 change: 0 additions & 1 deletion client/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ func TestSetHostHeader(t *testing.T) {
}

for _, tc := range testCases {
tc := tc
t.Run(tc.host, func(t *testing.T) {
hostURL, err := ParseHostURL(tc.host)
assert.Check(t, err)
Expand Down
2 changes: 1 addition & 1 deletion container/view.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// FIXME(thaJeztah): remove once we are a module; the go:build directive prevents go from downgrading language version to go1.16:
//go:build go1.21
//go:build go1.22

package container // import "github.com/docker/docker/container"

Expand Down
21 changes: 9 additions & 12 deletions daemon/cluster/convert/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func TestServiceConvertFromGRPCIsolation(t *testing.T) {
}

func TestServiceConvertToGRPCCredentialSpec(t *testing.T) {
cases := []struct {
tests := []struct {
name string
from swarmtypes.CredentialSpec
to swarmapi.Privileges_CredentialSpec
Expand Down Expand Up @@ -308,22 +308,21 @@ func TestServiceConvertToGRPCCredentialSpec(t *testing.T) {
},
}

for _, c := range cases {
c := c
t.Run(c.name, func(t *testing.T) {
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
s := swarmtypes.ServiceSpec{
TaskTemplate: swarmtypes.TaskSpec{
ContainerSpec: &swarmtypes.ContainerSpec{
Privileges: &swarmtypes.Privileges{
CredentialSpec: &c.from,
CredentialSpec: &tc.from,
},
},
},
}

res, err := ServiceSpecToGRPC(s)
if c.expectedErr != "" {
assert.Error(t, err, c.expectedErr)
if tc.expectedErr != "" {
assert.Error(t, err, tc.expectedErr)
return
}

Expand All @@ -332,13 +331,13 @@ func TestServiceConvertToGRPCCredentialSpec(t *testing.T) {
if !ok {
t.Fatal("expected type swarmapi.TaskSpec_Container")
}
assert.DeepEqual(t, c.to, *v.Container.Privileges.CredentialSpec)
assert.DeepEqual(t, tc.to, *v.Container.Privileges.CredentialSpec)
})
}
}

func TestServiceConvertFromGRPCCredentialSpec(t *testing.T) {
cases := []struct {
tests := []struct {
name string
from swarmapi.Privileges_CredentialSpec
to *swarmtypes.CredentialSpec
Expand Down Expand Up @@ -371,9 +370,7 @@ func TestServiceConvertFromGRPCCredentialSpec(t *testing.T) {
},
}

for _, tc := range cases {
tc := tc

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
gs := swarmapi.Service{
Spec: swarmapi.ServiceSpec{
Expand Down
2 changes: 0 additions & 2 deletions daemon/cluster/convert/volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ func TestVolumeAvailabilityFromGRPC(t *testing.T) {
expected: volumetypes.AvailabilityDrain,
},
} {
tc := tc
t.Run(tc.name, func(t *testing.T) {
actual := volumeAvailabilityFromGRPC(tc.in)
assert.Equal(t, actual, tc.expected)
Expand Down Expand Up @@ -113,7 +112,6 @@ func TestAccessModeFromGRPC(t *testing.T) {
},
},
} {
tc := tc
t.Run(tc.name, func(t *testing.T) {
out := accessModeFromGRPC(tc.in)
assert.DeepEqual(t, tc.expected, out)
Expand Down
1 change: 0 additions & 1 deletion daemon/cluster/executor/container/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,6 @@ func (c *containerAdapter) remove(ctx context.Context) error {
func (c *containerAdapter) createVolumes(ctx context.Context) error {
// Create plugin volumes that are embedded inside a Mount
for _, mount := range c.container.task.Spec.GetContainer().Mounts {
mount := mount
if mount.Type != api.MountTypeVolume {
continue
}
Expand Down
Loading

0 comments on commit a95a678

Please sign in to comment.