daemon: remove redundant capturing of loop vars (copyloopvar)

daemon/daemon_unix_test.go:277:3: The copy of the 'for' variable "tc" can be deleted (Go 1.22+) (copyloopvar)
            tc := tc
            ^
    daemon/delete_test.go:71:3: The copy of the 'for' variable "tc" can be deleted (Go 1.22+) (copyloopvar)
            tc := tc
            ^
    daemon/exec_linux_test.go:65:4: The copy of the 'for' variable "tc" can be deleted (Go 1.22+) (copyloopvar)
                tc := tc
                ^
    daemon/info_unix_test.go:54:3: The copy of the 'for' variable "test" can be deleted (Go 1.22+) (copyloopvar)
            test := test
            ^
    daemon/runtime_unix_test.go:173:3: The copy of the 'for' variable "tc" can be deleted (Go 1.22+) (copyloopvar)
            tc := tc
            ^
    daemon/runtime_unix_test.go:333:3: The copy of the 'for' variable "tt" can be deleted (Go 1.22+) (copyloopvar)
            tt := tt
            ^
    daemon/seccomp_linux_test.go:194:3: The copy of the 'for' variable "x" can be deleted (Go 1.22+) (copyloopvar)
            x := x
            ^
    daemon/top_unix_test.go:88:3: The copy of the 'for' variable "tc" can be deleted (Go 1.22+) (copyloopvar)
            tc := tc
            ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2024-11-12 13:37:59 +01:00
parent d885d097ef
commit b5c0f6cd70
7 changed files with 26 additions and 34 deletions

View File

@@ -274,7 +274,6 @@ func TestVerifyPlatformContainerResources(t *testing.T) {
},
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
warnings, err := verifyPlatformContainerResources(&tc.resources, &tc.sysInfo, tc.update)

View File

@@ -68,7 +68,6 @@ func TestContainerDelete(t *testing.T) {
}
for _, tc := range tests {
tc := tc
t.Run(tc.doc, func(t *testing.T) {
c := tc.initContainer()
d, cleanup := newDaemonWithTmpRoot(t)

View File

@@ -62,7 +62,6 @@ func TestExecSetPlatformOptAppArmor(t *testing.T) {
// both give the same result.
for _, execPrivileged := range []bool{false, true} {
for _, tc := range tests {
tc := tc
doc := tc.doc
if !appArmorEnabled {
// no profile should be set if the host does not support AppArmor

View File

@@ -50,17 +50,16 @@ func TestParseInitVersion(t *testing.T) {
},
}
for _, test := range tests {
test := test
t.Run(test.output, func(t *testing.T) {
version, commit, err := parseInitVersion(test.output)
if test.invalid {
for _, tc := range tests {
t.Run(tc.output, func(t *testing.T) {
version, commit, err := parseInitVersion(tc.output)
if tc.invalid {
assert.Check(t, is.ErrorContains(err, ""))
} else {
assert.Check(t, err)
}
assert.Equal(t, test.version, version)
assert.Equal(t, test.commit, commit)
assert.Equal(t, tc.version, version)
assert.Equal(t, tc.commit, commit)
})
}
}
@@ -117,15 +116,15 @@ spec: 1.0.0
},
}
for _, test := range tests {
runtime, version, commit, err := parseRuntimeVersion(test.output)
if test.invalid {
for _, tc := range tests {
runtime, version, commit, err := parseRuntimeVersion(tc.output)
if tc.invalid {
assert.Check(t, is.ErrorContains(err, ""))
} else {
assert.Check(t, err)
}
assert.Equal(t, test.runtime, runtime)
assert.Equal(t, test.version, version)
assert.Equal(t, test.commit, commit)
assert.Equal(t, tc.runtime, runtime)
assert.Equal(t, tc.version, version)
assert.Equal(t, tc.commit, commit)
}
}

View File

@@ -22,7 +22,7 @@ import (
)
func TestSetupRuntimes(t *testing.T) {
cases := []struct {
tests := []struct {
name string
config *config.Config
expectErr string
@@ -169,8 +169,7 @@ func TestSetupRuntimes(t *testing.T) {
},
},
}
for _, tc := range cases {
tc := tc
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
cfg, err := config.New()
assert.NilError(t, err)
@@ -251,7 +250,7 @@ func TestGetRuntime(t *testing.T) {
Opts: configdOpts,
}
for _, tt := range []struct {
for _, tc := range []struct {
name, runtime string
want *shimConfig
}{
@@ -330,13 +329,12 @@ func TestGetRuntime(t *testing.T) {
},
},
} {
tt := tt
t.Run(tt.name, func(t *testing.T) {
shim, opts, err := runtimes.Get(tt.runtime)
if tt.want != nil {
t.Run(tc.name, func(t *testing.T) {
shim, opts, err := runtimes.Get(tc.runtime)
if tc.want != nil {
assert.Check(t, err)
got := &shimConfig{Shim: shim, Opts: opts}
assert.Check(t, is.DeepEqual(got, tt.want,
assert.Check(t, is.DeepEqual(got, tc.want,
cmpopts.IgnoreUnexported(runtimeoptions_v1.Options{}),
cmpopts.IgnoreUnexported(v2runcoptions.Options{}),
))

View File

@@ -24,7 +24,7 @@ func TestWithSeccomp(t *testing.T) {
comment string
}
for _, x := range []expected{
for _, tc := range []expected{
{
comment: "unconfined seccompProfile runs unconfined",
daemon: &Daemon{
@@ -191,14 +191,13 @@ func TestWithSeccomp(t *testing.T) {
}(),
},
} {
x := x
t.Run(x.comment, func(t *testing.T) {
opts := WithSeccomp(x.daemon, x.c)
err := opts(nil, nil, nil, &x.inSpec)
t.Run(tc.comment, func(t *testing.T) {
opts := WithSeccomp(tc.daemon, tc.c)
err := opts(nil, nil, nil, &tc.inSpec)
assert.DeepEqual(t, x.inSpec, x.outSpec)
if x.err != "" {
assert.Error(t, err, x.err)
assert.DeepEqual(t, tc.inSpec, tc.outSpec)
if tc.err != "" {
assert.Error(t, err, tc.err)
} else {
assert.NilError(t, err)
}

View File

@@ -85,7 +85,6 @@ func TestContainerTopParsePSOutput(t *testing.T) {
}
for _, tc := range tests {
tc := tc
t.Run(string(tc.output), func(t *testing.T) {
_, err := parsePSOutput(tc.output, tc.pids)
if tc.errExpected && err == nil {