Fix incorrect use of loop variable in parallel tests (#2389)

This fixes occurences of a loop variable being captured in parallel
tests. With the previous code, only the last test case is actually
exercised. To work around this problem, we create a local copy of the
range variable before the parallel test, as suggested in the
documentation for the `testing` package:

https://pkg.go.dev/testing#hdr-Subtests_and_Sub_benchmarks

Issues were found automatically using the `loopvarcapture` linter.
pull/2390/head
Renato Costa 4 years ago committed by GitHub
parent b43e61c8c7
commit ec3d2ef360
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -78,6 +78,7 @@ func TestValidateCreateRequest(t *testing.T) {
},
}
for _, tc := range cases {
tc := tc // capture range variable
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
req := &pbs.CreateManagedGroupRequest{Item: tc.item}
@ -126,6 +127,7 @@ func TestValidateUpdateRequest(t *testing.T) {
},
}
for _, tc := range cases {
tc := tc // capture range variable
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
err := validateUpdateRequest(tc.req)

Loading…
Cancel
Save