From 1448cecba17f26a78c87f79c7b39ee5858e42382 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 5 Nov 2024 09:58:38 +0100 Subject: [PATCH] cli/compose: 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 --- cli/compose/convert/service_test.go | 2 -- cli/compose/loader/loader_test.go | 9 ++++----- cli/compose/schema/schema_test.go | 1 - cli/compose/template/template_test.go | 1 - 4 files changed, 4 insertions(+), 9 deletions(-) diff --git a/cli/compose/convert/service_test.go b/cli/compose/convert/service_test.go index 22f585f87c..a7c8bf28ca 100644 --- a/cli/compose/convert/service_test.go +++ b/cli/compose/convert/service_test.go @@ -409,7 +409,6 @@ func TestConvertCredentialSpec(t *testing.T) { } for _, tc := range tests { - tc := tc t.Run(tc.name, func(t *testing.T) { namespace := NewNamespace(tc.name) swarmSpec, err := convertCredentialSpec(namespace, tc.in, tc.configs) @@ -691,7 +690,6 @@ func TestConvertServiceCapAddAndCapDrop(t *testing.T) { }, } for _, tc := range tests { - tc := tc t.Run(tc.title, func(t *testing.T) { result, err := Service("1.41", Namespace{name: "foo"}, tc.in, nil, nil, nil, nil) assert.NilError(t, err) diff --git a/cli/compose/loader/loader_test.go b/cli/compose/loader/loader_test.go index 47a30ebd0e..c1d7af3641 100644 --- a/cli/compose/loader/loader_test.go +++ b/cli/compose/loader/loader_test.go @@ -1626,13 +1626,12 @@ services: init: &booleanFalse, }, } - for _, testcase := range testcases { - testcase := testcase - t.Run(testcase.doc, func(t *testing.T) { - config, err := loadYAML(testcase.yaml) + for _, tc := range testcases { + t.Run(tc.doc, func(t *testing.T) { + config, err := loadYAML(tc.yaml) assert.NilError(t, err) assert.Check(t, is.Len(config.Services, 1)) - assert.Check(t, is.DeepEqual(testcase.init, config.Services[0].Init)) + assert.Check(t, is.DeepEqual(tc.init, config.Services[0].Init)) }) } } diff --git a/cli/compose/schema/schema_test.go b/cli/compose/schema/schema_test.go index 33a992a362..9738494156 100644 --- a/cli/compose/schema/schema_test.go +++ b/cli/compose/schema/schema_test.go @@ -215,7 +215,6 @@ func TestValidateCredentialSpecs(t *testing.T) { } for _, tc := range tests { - tc := tc t.Run(tc.version, func(t *testing.T) { config := dict{ "version": "99.99", diff --git a/cli/compose/template/template_test.go b/cli/compose/template/template_test.go index 0d0a92e709..5482342f80 100644 --- a/cli/compose/template/template_test.go +++ b/cli/compose/template/template_test.go @@ -277,7 +277,6 @@ func TestExtractVariables(t *testing.T) { }, } for _, tc := range testCases { - tc := tc t.Run(tc.name, func(t *testing.T) { actual := ExtractVariables(tc.dict, defaultPattern) assert.Check(t, is.DeepEqual(actual, tc.expected))