Skip to content

Commit f91437c

Browse files
committed
Fix for-range scope issues
1 parent 719e522 commit f91437c

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

path_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ func TestPathCleanMallocs(t *testing.T) {
8383
}
8484

8585
for _, test := range cleanTests {
86+
test := test
8687
allocs := testing.AllocsPerRun(100, func() { CleanPath(test.result) })
8788
if allocs > 0 {
8889
t.Errorf("CleanPath(%q): %v allocs, want zero", test.result, allocs)

tree_test.go

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,8 @@ type testRoute struct {
202202
func testRoutes(t *testing.T, routes []testRoute) {
203203
tree := &node{}
204204

205-
for _, route := range routes {
205+
for i := range routes {
206+
route := routes[i]
206207
recv := catchPanic(func() {
207208
tree.addRoute(route.path, nil)
208209
})
@@ -266,7 +267,8 @@ func TestTreeDupliatePath(t *testing.T) {
266267
"/search/:query",
267268
"/user_:name",
268269
}
269-
for _, route := range routes {
270+
for i := range routes {
271+
route := routes[i]
270272
recv := catchPanic(func() {
271273
tree.addRoute(route, fakeHandler(route))
272274
})
@@ -303,7 +305,8 @@ func TestEmptyWildcardName(t *testing.T) {
303305
"/cmd/:/",
304306
"/src/*",
305307
}
306-
for _, route := range routes {
308+
for i := range routes {
309+
route := routes[i]
307310
recv := catchPanic(func() {
308311
tree.addRoute(route, nil)
309312
})
@@ -347,7 +350,8 @@ func TestTreeDoubleWildcard(t *testing.T) {
347350
"/:foo*bar",
348351
}
349352

350-
for _, route := range routes {
353+
for i := range routes {
354+
route := routes[i]
351355
tree := &node{}
352356
recv := catchPanic(func() {
353357
tree.addRoute(route, nil)
@@ -399,7 +403,8 @@ func TestTreeTrailingSlashRedirect(t *testing.T) {
399403
"/no/b",
400404
"/api/hello/:name",
401405
}
402-
for _, route := range routes {
406+
for i := range routes {
407+
route := routes[i]
403408
recv := catchPanic(func() {
404409
tree.addRoute(route, fakeHandler(route))
405410
})
@@ -513,7 +518,8 @@ func TestTreeFindCaseInsensitivePath(t *testing.T) {
513518
longPath,
514519
}
515520

516-
for _, route := range routes {
521+
for i := range routes {
522+
route := routes[i]
517523
recv := catchPanic(func() {
518524
tree.addRoute(route, fakeHandler(route))
519525
})
@@ -524,7 +530,8 @@ func TestTreeFindCaseInsensitivePath(t *testing.T) {
524530

525531
// Check out == in for all registered routes
526532
// With fixTrailingSlash = true
527-
for _, route := range routes {
533+
for i := range routes {
534+
route := routes[i]
528535
out, found := tree.findCaseInsensitivePath(route, true)
529536
if !found {
530537
t.Errorf("Route '%s' not found!", route)
@@ -533,7 +540,8 @@ func TestTreeFindCaseInsensitivePath(t *testing.T) {
533540
}
534541
}
535542
// With fixTrailingSlash = false
536-
for _, route := range routes {
543+
for i := range routes {
544+
route := routes[i]
537545
out, found := tree.findCaseInsensitivePath(route, false)
538546
if !found {
539547
t.Errorf("Route '%s' not found!", route)
@@ -672,7 +680,9 @@ func TestTreeWildcardConflictEx(t *testing.T) {
672680
{"/conooo/xxx", "ooo", `/con:tact`, `:tact`},
673681
}
674682

675-
for _, conflict := range conflicts {
683+
for i := range conflicts {
684+
conflict := conflicts[i]
685+
676686
// I have to re-create a 'tree', because the 'tree' will be
677687
// in an inconsistent state when the loop recovers from the
678688
// panic which threw by 'addRoute' function.
@@ -683,7 +693,8 @@ func TestTreeWildcardConflictEx(t *testing.T) {
683693
"/who/foo/hello",
684694
}
685695

686-
for _, route := range routes {
696+
for i := range routes {
697+
route := routes[i]
687698
tree.addRoute(route, fakeHandler(route))
688699
}
689700

0 commit comments

Comments
 (0)