Skip to content

Commit

Permalink
chore: Add copyloopvar to linters and autofix all the files
Browse files Browse the repository at this point in the history
This removes pre 1.22 copying of values in a lot of tests with table
tests.
  • Loading branch information
mstoykov committed Mar 6, 2025
1 parent f92772d commit 74968a6
Show file tree
Hide file tree
Showing 108 changed files with 12 additions and 318 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ linters:
- canonicalheader
- contextcheck
- cyclop
- copyloopvar
- dogsled
- dupl
- durationcheck
Expand Down
1 change: 0 additions & 1 deletion api/v1/group_routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ func TestGetGroups(t *testing.T) {
})
})
for _, gp := range []*lib.Group{g0, g1, g2} {
gp := gp
t.Run(gp.Name, func(t *testing.T) {
t.Parallel()
rw := httptest.NewRecorder()
Expand Down
1 change: 0 additions & 1 deletion api/v1/setup_teardown_routes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ func TestSetupData(t *testing.T) {
}

for id := range testCases {
id := id
t.Run(fmt.Sprintf("testcase_%d", id), func(t *testing.T) {
t.Parallel()
runTestCase(t, id)
Expand Down
1 change: 0 additions & 1 deletion cloudapi/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ func TestRetry(t *testing.T) {
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
var sleepRequests []time.Duration
Expand Down
2 changes: 0 additions & 2 deletions internal/api/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@ func testHTTPHandler(rw http.ResponseWriter, _ *http.Request) {
func TestLogger(t *testing.T) {
t.Parallel()
for _, method := range []string{"GET", "POST", "PUT", "PATCH"} {
method := method
t.Run("method="+method, func(t *testing.T) {
t.Parallel()
for _, path := range []string{"/", "/test", "/test/path"} {
path := path
t.Run("path="+path, func(t *testing.T) {
t.Parallel()
rw := httptest.NewRecorder()
Expand Down
1 change: 0 additions & 1 deletion internal/cmd/archive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ func TestArchiveThresholds(t *testing.T) {
}

for _, testCase := range testCases {
testCase := testCase
t.Run(testCase.name, func(t *testing.T) {
t.Parallel()

Expand Down
4 changes: 0 additions & 4 deletions internal/cmd/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,9 @@ func TestConfigCmd(t *testing.T) {
}

for _, data := range testdata {
data := data
t.Run(data.Name, func(t *testing.T) {
t.Parallel()
for _, test := range data.Tests {
test := test
t.Run(`"`+test.Name+`"`, func(t *testing.T) {
t.Parallel()
fs := configFlagSet()
Expand Down Expand Up @@ -193,7 +191,6 @@ func TestDeriveAndValidateConfig(t *testing.T) {
}

for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
_, err := deriveAndValidateConfig(tc.conf,
Expand Down Expand Up @@ -499,7 +496,6 @@ func TestLoadConfig(t *testing.T) {
},
}
for _, tc := range testcases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
l, hook := testutils.NewLoggerWithHook(t)
Expand Down
1 change: 0 additions & 1 deletion internal/cmd/new_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ func TestNewScriptCmd(t *testing.T) {
}

for _, testCase := range testCases {
testCase := testCase
t.Run(testCase.name, func(t *testing.T) {
t.Parallel()

Expand Down
1 change: 0 additions & 1 deletion internal/cmd/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ func TestParseTagKeyValue(t *testing.T) {
}

for _, data := range testData {
data := data
t.Run(data.input, func(t *testing.T) {
t.Parallel()
name, value, err := parseTagNameValue(data.input)
Expand Down
2 changes: 0 additions & 2 deletions internal/cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ func TestRootCommandHelpDisplayCommands(t *testing.T) {
}

for _, tc := range testCases {
tc := tc

t.Run(tc.name, func(t *testing.T) {
t.Parallel()

Expand Down
1 change: 0 additions & 1 deletion internal/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,6 @@ func (c *cmdRun) run(cmd *cobra.Command, args []string) (err error) {
var wg sync.WaitGroup
wg.Add(len(ww))
for _, w := range ww {
w := w
go func() {
w()
wg.Done()
Expand Down
6 changes: 1 addition & 5 deletions internal/cmd/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ func TestRunScriptErrorsAndAbort(t *testing.T) {
}

for _, tc := range testCases {
tc := tc

name := tc.testFilename
if tc.name != "" {
name = fmt.Sprintf("%s (%s)", tc.testFilename, tc.name)
Expand Down Expand Up @@ -293,8 +293,6 @@ func TestInvalidOptionsThresholdErrExitCode(t *testing.T) {
}

for _, tc := range testCases {
tc := tc

t.Run(tc.name, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -343,8 +341,6 @@ func TestThresholdsRuntimeBehavior(t *testing.T) {
}

for _, tc := range testCases {
tc := tc

t.Run(tc.name, func(t *testing.T) {
t.Parallel()

Expand Down
1 change: 0 additions & 1 deletion internal/cmd/runtime_options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,6 @@ func TestRuntimeOptions(t *testing.T) {
},
}
for name, tc := range runtimeOptionsTestCases {
tc := tc
t.Run(fmt.Sprintf("RuntimeOptions test '%s'", name), func(t *testing.T) {
t.Parallel()
testRuntimeOptionsCase(t, tc)
Expand Down
2 changes: 0 additions & 2 deletions internal/cmd/tests/cmd_cloud_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ func TestCloudRunCommandIncompatibleFlags(t *testing.T) {
}

for _, tc := range testCases {
tc := tc

t.Run(tc.name, func(t *testing.T) {
t.Parallel()

Expand Down
3 changes: 0 additions & 3 deletions internal/cmd/tests/cmd_run_grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,6 @@ func TestGRPCInputOutput(t *testing.T) {
require.NoError(t, err)

for name, test := range tc {
name := name
test := test

t.Run(name, func(t *testing.T) {
t.Parallel()

Expand Down
10 changes: 0 additions & 10 deletions internal/cmd/tests/cmd_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1884,8 +1884,6 @@ func TestUIRenderOutput(t *testing.T) {
}

for _, tc := range tests {
tc := tc

t.Run(tc.expRender, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -1919,8 +1917,6 @@ func TestUIRenderWebDashboard(t *testing.T) {
}

for _, tc := range tests {
tc := tc

t.Run(tc.expRender, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -1963,8 +1959,6 @@ func TestRunStaticArchives(t *testing.T) {
}

for _, tc := range tests {
tc := tc

t.Run("Using "+tc.archive, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -1997,8 +1991,6 @@ func TestBadLogOutput(t *testing.T) {
}

for name, tc := range cases {
name := name
tc := tc
t.Run(name, func(t *testing.T) {
t.Parallel()
ts := NewGlobalTestState(t)
Expand Down Expand Up @@ -2141,7 +2133,6 @@ func TestEventSystemError(t *testing.T) {
}

for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
ts := NewGlobalTestState(t)
Expand Down Expand Up @@ -2287,7 +2278,6 @@ func TestBrowserPermissions(t *testing.T) {
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
script := fmt.Sprintf(`
Expand Down
1 change: 0 additions & 1 deletion internal/cmd/ui_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ left 2 [ 0% ] right 2 000
}

for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
pbs := createTestProgressBars(3, tc.padding, 1)
Expand Down
2 changes: 1 addition & 1 deletion internal/event/system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func TestEventSystem(t *testing.T) {
data int
)
for _, et := range emitEvents {
et := et

evt := &Event{Type: et, Data: data, Done: func() {
doneMx.Lock()
processed[et]++
Expand Down
1 change: 0 additions & 1 deletion internal/execution/scheduler_ext_exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,6 @@ func TestExecutionInfoAll(t *testing.T) {
}

for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()

Expand Down
5 changes: 0 additions & 5 deletions internal/execution/scheduler_ext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ func TestSchedulerRunNonDefault(t *testing.T) {
}

for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
piState := getTestPreInitState(t)
Expand Down Expand Up @@ -247,7 +246,6 @@ func TestSchedulerRunEnv(t *testing.T) {
}

for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
piState := getTestPreInitState(t)
Expand Down Expand Up @@ -462,7 +460,6 @@ func TestSchedulerRunCustomTags(t *testing.T) {
}

for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
piState := getTestPreInitState(t)
Expand Down Expand Up @@ -843,7 +840,6 @@ func TestSchedulerStages(t *testing.T) {
}

for name, data := range testdata {
data := data
t.Run(name, func(t *testing.T) {
t.Parallel()
runner := &minirunner.MiniRunner{
Expand Down Expand Up @@ -1099,7 +1095,6 @@ func TestDNSResolverCache(t *testing.T) {
}

for name, tc := range testCases {
tc := tc
t.Run(name, func(t *testing.T) {
t.Parallel()
logger := logrus.New()
Expand Down
7 changes: 0 additions & 7 deletions internal/js/bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ func TestNewBundle(t *testing.T) {
}

for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
rtOpts := lib.RuntimeOptions{CompatibilityMode: null.StringFrom(tc.compatMode)}
Expand Down Expand Up @@ -710,7 +709,6 @@ func TestOpen(t *testing.T) {
t.Run(name, func(t *testing.T) {
t.Parallel()
for _, tCase := range testCases {
tCase := tCase

testFunc := func(t *testing.T) {
t.Parallel()
Expand Down Expand Up @@ -742,7 +740,6 @@ func TestOpen(t *testing.T) {
require.NoError(t, err)

for source, b := range map[string]*Bundle{"source": sourceBundle, "archive": arcBundle} {
b := b
t.Run(source, func(t *testing.T) {
bi, err := b.Instantiate(context.Background(), 0)
require.NoError(t, err)
Expand Down Expand Up @@ -841,7 +838,6 @@ func TestBundleEnv(t *testing.T) {

bundles := map[string]*Bundle{"Source": b1, "Archive": b2}
for name, b := range bundles {
b := b
t.Run(name, func(t *testing.T) {
t.Parallel()
require.Equal(t, "1", b.preInitState.RuntimeOptions.Env["TEST_A"])
Expand Down Expand Up @@ -879,7 +875,6 @@ func TestBundleNotSharable(t *testing.T) {
bundles := map[string]*Bundle{"Source": b1, "Archive": b2}
var vus, iters uint64 = 10, 1000
for name, b := range bundles {
b := b
t.Run(name, func(t *testing.T) {
t.Parallel()
for i := uint64(0); i < vus; i++ {
Expand Down Expand Up @@ -921,7 +916,6 @@ func TestBundleMakeArchive(t *testing.T) {
}

for _, tc := range testCases {
tc := tc
t.Run(tc.cm.String(), func(t *testing.T) {
t.Parallel()
fs := fsext.NewMemMapFs()
Expand Down Expand Up @@ -982,7 +976,6 @@ func TestGlobalTimers(t *testing.T) {

bundles := map[string]*Bundle{"Source": b1, "Archive": b2}
for name, b := range bundles {
b := b
t.Run(name, func(t *testing.T) {
t.Parallel()
_, err := b.Instantiate(context.Background(), 1)
Expand Down
3 changes: 0 additions & 3 deletions internal/js/console_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,6 @@ func TestConsoleLogObjectsWithGoTypes(t *testing.T) {

expFields := logrus.Fields{"source": "console"}
for _, tt := range tests {
tt := tt

t.Run(tt.name, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -242,7 +240,6 @@ func TestConsoleLog(t *testing.T) {
}

for i, tt := range tests {
tt := tt
t.Run(fmt.Sprintf("case%d", i), func(t *testing.T) {
t.Parallel()

Expand Down
2 changes: 0 additions & 2 deletions internal/js/initcontext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@ func TestInitContextOpen(t *testing.T) {
// {[]byte{00, 36, 32, 127}, "utf-16", 2}, // $€
}
for _, tc := range testCases {
tc := tc
t.Run(tc.file, func(t *testing.T) {
t.Parallel()
bi, err := createAndReadFile(t, tc.file, tc.content, tc.length, "")
Expand All @@ -266,7 +265,6 @@ func TestInitContextOpen(t *testing.T) {
}

for name, loadPath := range testdata {
loadPath := loadPath
t.Run(name, func(t *testing.T) {
t.Parallel()
_, err := createAndReadFile(t, loadPath, []byte("content"), 7, "")
Expand Down
Loading

0 comments on commit 74968a6

Please sign in to comment.