From 762b5a8df32159df86bcab317f339a5952632e2d Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Tue, 5 Nov 2024 10:00:31 +0100 Subject: [PATCH] opts: 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 --- opts/capabilities_test.go | 2 -- opts/config_test.go | 1 - opts/env_test.go | 1 - opts/hosts_test.go | 1 - opts/network_test.go | 2 -- opts/opts_test.go | 2 -- opts/parse_test.go | 1 - opts/port_test.go | 1 - opts/secret_test.go | 1 - 9 files changed, 12 deletions(-) diff --git a/opts/capabilities_test.go b/opts/capabilities_test.go index 32c50d06a1..06a23d50dc 100644 --- a/opts/capabilities_test.go +++ b/opts/capabilities_test.go @@ -36,7 +36,6 @@ func TestNormalizeCapability(t *testing.T) { } for _, tc := range tests { - tc := tc t.Run(tc.in, func(t *testing.T) { assert.Equal(t, NormalizeCapability(tc.in), tc.out) }) @@ -108,7 +107,6 @@ func TestEffectiveCapAddCapDrop(t *testing.T) { } for i, tc := range tests { - tc := tc t.Run(strconv.Itoa(i), func(t *testing.T) { add, drop := EffectiveCapAddCapDrop(tc.in.add, tc.in.drop) assert.DeepEqual(t, add, tc.out.add) diff --git a/opts/config_test.go b/opts/config_test.go index 15334e5f7f..ab7d0c5b2b 100644 --- a/opts/config_test.go +++ b/opts/config_test.go @@ -64,7 +64,6 @@ func TestConfigOptions(t *testing.T) { } for _, tc := range testCases { - tc := tc t.Run(tc.name, func(t *testing.T) { var opt ConfigOpt assert.NilError(t, opt.Set(tc.input)) diff --git a/opts/env_test.go b/opts/env_test.go index a8a565be2a..ff3d3e2ac6 100644 --- a/opts/env_test.go +++ b/opts/env_test.go @@ -104,7 +104,6 @@ func TestValidateEnv(t *testing.T) { } for _, tc := range tests { - tc := tc t.Run(tc.value, func(t *testing.T) { actual, err := ValidateEnv(tc.value) diff --git a/opts/hosts_test.go b/opts/hosts_test.go index f33c915f03..f1096c4f64 100644 --- a/opts/hosts_test.go +++ b/opts/hosts_test.go @@ -281,7 +281,6 @@ func TestValidateExtraHosts(t *testing.T) { } for _, tc := range tests { - tc := tc if tc.expectedOut == "" { tc.expectedOut = tc.input } diff --git a/opts/network_test.go b/opts/network_test.go index e44ce3490b..722062bd7d 100644 --- a/opts/network_test.go +++ b/opts/network_test.go @@ -114,7 +114,6 @@ func TestNetworkOptAdvancedSyntax(t *testing.T) { }, } for _, tc := range testCases { - tc := tc t.Run(tc.value, func(t *testing.T) { var network NetworkOpt assert.NilError(t, network.Set(tc.value)) @@ -142,7 +141,6 @@ func TestNetworkOptAdvancedSyntaxInvalid(t *testing.T) { }, } for _, tc := range testCases { - tc := tc t.Run(tc.value, func(t *testing.T) { var network NetworkOpt assert.ErrorContains(t, network.Set(tc.value), tc.expectedError) diff --git a/opts/opts_test.go b/opts/opts_test.go index 9bf9dd12d2..14a36825a2 100644 --- a/opts/opts_test.go +++ b/opts/opts_test.go @@ -69,7 +69,6 @@ func TestValidateIPAddress(t *testing.T) { } for _, tc := range tests { - tc := tc t.Run(tc.input, func(t *testing.T) { actualOut, actualErr := ValidateIPAddress(tc.input) assert.Check(t, is.Equal(tc.expectedOut, actualOut)) @@ -339,7 +338,6 @@ func TestValidateLabel(t *testing.T) { } for _, tc := range tests { - tc := tc t.Run(tc.name, func(t *testing.T) { val, err := ValidateLabel(tc.value) if tc.expectedErr != "" { diff --git a/opts/parse_test.go b/opts/parse_test.go index f7ab13a299..731b5f226e 100644 --- a/opts/parse_test.go +++ b/opts/parse_test.go @@ -61,7 +61,6 @@ NO_SUCH_ENV } for _, tc := range tests { - tc := tc t.Run(tc.name, func(t *testing.T) { envs, err := ReadKVEnvStrings(tc.files, tc.overrides) assert.NilError(t, err) diff --git a/opts/port_test.go b/opts/port_test.go index a64e6e57ec..06d19fce39 100644 --- a/opts/port_test.go +++ b/opts/port_test.go @@ -344,7 +344,6 @@ func TestConvertPortToPortConfigWithIP(t *testing.T) { var b bytes.Buffer logrus.SetOutput(&b) for _, tc := range testCases { - tc := tc t.Run(tc.value, func(t *testing.T) { _, err := ConvertPortToPortConfig("80/tcp", map[nat.Port][]nat.PortBinding{ "80/tcp": {{HostIP: tc.value, HostPort: "2345"}}, diff --git a/opts/secret_test.go b/opts/secret_test.go index eaafaaf2e6..88f4f96027 100644 --- a/opts/secret_test.go +++ b/opts/secret_test.go @@ -64,7 +64,6 @@ func TestSecretOptions(t *testing.T) { } for _, tc := range testCases { - tc := tc t.Run(tc.name, func(t *testing.T) { var opt SecretOpt assert.NilError(t, opt.Set(tc.input))