Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix incorrect use of loop variable #16872

Merged
merged 1 commit into from
Oct 4, 2022

Commits on Oct 3, 2022

  1. fix incorrect use of loop variable

    This fixes a couple of references to loop variables in parallel tests
    and deferred functions. When running a parallel test (calling
    `t.Parallel()`) combined with the table-driven pattern, it's necessary
    to copy the test case loop variable, otherwise only the last test case
    is exercised. This is documented in the `testing` package:
    
    https://pkg.go.dev/testing#hdr-Subtests_and_Sub_benchmarks
    
    `defer` statements that invoke a closure should also not reference a
    loop variable directly as the referenced value will change in each
    iteration of the loop.
    
    Issues were automatically found with the `loopvarcapture` linter.
    renatolabs committed Oct 3, 2022
    Configuration menu
    Copy the full SHA
    5235770 View commit details
    Browse the repository at this point in the history