Skip to content

Commit ca2deb9

Browse files
authored
refactor: Remove unnecessary loop vars (#1146)
Since go 1.22 capturing loop variables is unnecessary so just tidying up. See https://go.dev/blog/loopvar-preview for more details.
1 parent 5890b05 commit ca2deb9

File tree

52 files changed

+61
-129
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+61
-129
lines changed

api/v1alpha1/http_proxy_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,7 @@ func TestGenerateNoProxy(t *testing.T) {
180180
},
181181
}}
182182

183-
for idx := range testCases {
184-
tt := testCases[idx]
185-
183+
for _, tt := range testCases {
186184
t.Run(tt.name, func(t *testing.T) {
187185
t.Parallel()
188186

common/pkg/capi/clustertopology/handlers/mutation/meta_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,7 @@ func TestMetaGeneratePatches(t *testing.T) {
212212
},
213213
}}
214214

215-
for idx := range tests {
216-
tt := tests[idx]
217-
215+
for _, tt := range tests {
218216
t.Run(tt.name, func(t *testing.T) {
219217
t.Parallel()
220218

common/pkg/capi/clustertopology/patches/generator_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,7 @@ func TestMutateIfApplicable(t *testing.T) {
123123
},
124124
},
125125
}}
126-
for testIdx := range tests {
127-
tt := tests[testIdx] // Capture loop var.
128-
126+
for _, tt := range tests {
129127
t.Run(tt.name, func(t *testing.T) {
130128
t.Parallel()
131129

common/pkg/capi/clustertopology/patches/matchers/match_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -479,9 +479,7 @@ func TestMatchesSelector(t *testing.T) {
479479
},
480480
match: false,
481481
}}
482-
for idx := range tests {
483-
tt := tests[idx]
484-
482+
for _, tt := range tests {
485483
t.Run(tt.name, func(t *testing.T) {
486484
t.Parallel()
487485

common/pkg/k8s/parser/parser_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,7 @@ metadata:
139139
func runUnstructuredTests(t *testing.T, fn func([]string) ([]client.Object, error)) {
140140
t.Helper()
141141
t.Parallel()
142-
for idx := range tests {
143-
tt := tests[idx]
142+
for _, tt := range tests {
144143
t.Run(tt.name, func(t *testing.T) {
145144
t.Parallel()
146145
got, err := fn(tt.inputs)

common/pkg/server/server.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,7 @@ func (s *Server) Start(ctx context.Context) error {
7979
return err
8080
}
8181

82-
for idx := range s.hooks {
83-
h := s.hooks[idx]
84-
82+
for _, h := range s.hooks {
8583
if t, ok := h.(lifecycle.BeforeClusterCreate); ok {
8684
if err := webhookServer.AddExtensionHandler(runtimeserver.ExtensionHandler{
8785
Hook: runtimehooksv1.BeforeClusterCreate,

common/pkg/testutils/capitest/variables.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,7 @@ func ValidateDiscoverVariables[T mutation.DiscoverVariables](
5656
"Schema": gomega.Equal(*variableSchema),
5757
}))
5858

59-
for idx := range variableTestDefs {
60-
tt := variableTestDefs[idx]
61-
59+
for _, tt := range variableTestDefs {
6260
t.Run(tt.Name, func(t *testing.T) {
6361
t.Parallel()
6462

pkg/handlers/aws/mutation/ami/inject_control_plane_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,7 @@ var _ = Describe("Generate AMI patches for ControlPlane", func() {
9090
}
9191

9292
// create test node for each case
93-
for testIdx := range testDefs {
94-
tt := testDefs[testIdx]
93+
for _, tt := range testDefs {
9594
It(tt.Name, func() {
9695
capitest.AssertGeneratePatches(
9796
GinkgoT(),

pkg/handlers/aws/mutation/ami/inject_worker_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ var _ = Describe("Generate AMI patches for Worker", func() {
9898
}
9999

100100
// create test node for each case
101-
for testIdx := range testDefs {
102-
tt := testDefs[testIdx]
101+
for _, tt := range testDefs {
103102
It(tt.Name, func() {
104103
capitest.AssertGeneratePatches(
105104
GinkgoT(),

pkg/handlers/aws/mutation/cni/calico/inject_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,7 @@ var _ = Describe("Generate AWS Calico CNI ingress patches", func() {
277277
}
278278

279279
// create test node for each case
280-
for testIdx := range testDefs {
281-
tt := testDefs[testIdx]
280+
for _, tt := range testDefs {
282281
It(tt.Name, func() {
283282
capitest.AssertGeneratePatches(
284283
GinkgoT(),

0 commit comments

Comments
 (0)