cmd/docker: remove redundant capturing of loop vars in tests (copyloopvar)

go1.22 and up now produce a unique variable in loops, tehrefore no longer
requiring to capture the variable manually;

    service/logs/parse_logs_test.go:50: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-05 10:00:17 +01:00
parent bf37e26b33
commit 417974cdc3
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
1 changed files with 14 additions and 16 deletions

View File

@ -64,14 +64,13 @@ echo '{"SchemaVersion":"0.1.0","Vendor":"Docker Inc.","Version":"v0.6.3","ShortD
) )
defer dir.Remove() defer dir.Remove()
for _, tt := range testcases { for _, tc := range testcases {
tt := tt t.Run(tc.name, func(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
ctx2, cancel2 := context.WithCancel(ctx) ctx2, cancel2 := context.WithCancel(ctx)
defer cancel2() defer cancel2()
if tt.builder != "" { if tc.builder != "" {
t.Setenv("BUILDX_BUILDER", tt.builder) t.Setenv("BUILDX_BUILDER", tc.builder)
} }
var b bytes.Buffer var b bytes.Buffer
@ -84,10 +83,10 @@ echo '{"SchemaVersion":"0.1.0","Vendor":"Docker Inc.","Version":"v0.6.3","ShortD
assert.NilError(t, err) assert.NilError(t, err)
assert.NilError(t, dockerCli.Initialize(flags.NewClientOptions())) assert.NilError(t, dockerCli.Initialize(flags.NewClientOptions()))
if tt.context != "" { if tc.context != "" {
if tt.context != command.DefaultContextName { if tc.context != command.DefaultContextName {
assert.NilError(t, dockerCli.ContextStore().CreateOrUpdate(store.Metadata{ assert.NilError(t, dockerCli.ContextStore().CreateOrUpdate(store.Metadata{
Name: tt.context, Name: tc.context,
Endpoints: map[string]any{ Endpoints: map[string]any{
"docker": map[string]any{ "docker": map[string]any{
"host": "unix://" + filepath.Join(t.TempDir(), "docker.sock"), "host": "unix://" + filepath.Join(t.TempDir(), "docker.sock"),
@ -96,12 +95,12 @@ echo '{"SchemaVersion":"0.1.0","Vendor":"Docker Inc.","Version":"v0.6.3","ShortD
})) }))
} }
opts := flags.NewClientOptions() opts := flags.NewClientOptions()
opts.Context = tt.context opts.Context = tc.context
assert.NilError(t, dockerCli.Initialize(opts)) assert.NilError(t, dockerCli.Initialize(opts))
} }
dockerCli.ConfigFile().CLIPluginsExtraDirs = []string{dir.Path()} dockerCli.ConfigFile().CLIPluginsExtraDirs = []string{dir.Path()}
if tt.alias { if tc.alias {
dockerCli.ConfigFile().Aliases = map[string]string{"builder": "buildx"} dockerCli.ConfigFile().Aliases = map[string]string{"builder": "buildx"}
} }
@ -115,8 +114,8 @@ echo '{"SchemaVersion":"0.1.0","Vendor":"Docker Inc.","Version":"v0.6.3","ShortD
args, os.Args, envs, err = processBuilder(dockerCli, cmd, args, os.Args) args, os.Args, envs, err = processBuilder(dockerCli, cmd, args, os.Args)
assert.NilError(t, err) assert.NilError(t, err)
assert.DeepEqual(t, []string{builderDefaultPlugin, "build", "."}, args) assert.DeepEqual(t, []string{builderDefaultPlugin, "build", "."}, args)
if tt.expectedEnvs != nil { if tc.expectedEnvs != nil {
assert.DeepEqual(t, tt.expectedEnvs, envs) assert.DeepEqual(t, tc.expectedEnvs, envs)
} else { } else {
assert.Check(t, len(envs) == 0) assert.Check(t, len(envs) == 0)
} }
@ -289,10 +288,9 @@ func TestHasBuilderName(t *testing.T) {
expected: true, expected: true,
}, },
} }
for _, tt := range cases { for _, tc := range cases {
tt := tt t.Run(tc.name, func(t *testing.T) {
t.Run(tt.name, func(t *testing.T) { assert.Equal(t, tc.expected, hasBuilderName(tc.args, tc.envs))
assert.Equal(t, tt.expected, hasBuilderName(tt.args, tt.envs))
}) })
} }
} }