From d521933053bdf68d252e365da9376706d04addcc Mon Sep 17 00:00:00 2001 From: Renato Costa <103441181+renatolabs@users.noreply.github.com> Date: Thu, 25 Aug 2022 06:23:29 -0400 Subject: [PATCH] Fix incorrect use of loop variable in parallel test (#11205) This fixes an occurrence of a loop variable being captured in a parallel test (`TestInitialUpdate`). Prior to this commit, only the last test case declared in that test would actually execute. To work around this problem, we create a copy of the range variable before the paralllel test, as suggested in the documentation for the `testing` package: https://pkg.go.dev/testing#hdr-Subtests_and_Sub_benchmarks The test immediately after the one fixed here (`TestInvalidFile`) followed the same pattern but correctly created a copy of the loop variable, illustrating how easy it is to forget to do this in practice. Issue was automatically found using the `loopvarcapture` linter. Signed-off-by: Renato Costa Signed-off-by: Renato Costa --- discovery/file/file_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/discovery/file/file_test.go b/discovery/file/file_test.go index e3b59b474..76e1cebed 100644 --- a/discovery/file/file_test.go +++ b/discovery/file/file_test.go @@ -308,6 +308,7 @@ func TestInitialUpdate(t *testing.T) { "fixtures/valid.yml", "fixtures/valid.json", } { + tc := tc t.Run(tc, func(t *testing.T) { t.Parallel()