Skip to content

Commit 023885c

Browse files
authored
chore: modernize with range over int (#4746)
A purely mechanical change with no effect on behaviour. Stops `gopls` from complaining. Corresponding spec, see here: golang/go#61405 Introduced in `Go 1.22`, see here: https://go.dev/ref/spec#For_range Signed-off-by: Solomon Jacobs <[email protected]>
1 parent ab315ea commit 023885c

File tree

9 files changed

+20
-20
lines changed

9 files changed

+20
-20
lines changed

dispatch/dispatch_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ func TestAggrGroup(t *testing.T) {
165165
}
166166
}
167167

168-
for i := 0; i < 3; i++ {
168+
for range 3 {
169169
// New alert should come in after group interval.
170170
ag.insert(a3)
171171

@@ -207,7 +207,7 @@ func TestAggrGroup(t *testing.T) {
207207
t.Fatalf("expected alerts %v but got %v", exp, batch)
208208
}
209209

210-
for i := 0; i < 3; i++ {
210+
for range 3 {
211211
// New alert should come in after group interval.
212212
ag.insert(a3)
213213

inhibit/inhibit_bench_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func allRulesMatchBenchmark(b *testing.B, numInhibitionRules, numInhibitingAlert
119119
},
120120
newAlertsFunc: func(idx int, _ config.InhibitRule) []types.Alert {
121121
var alerts []types.Alert
122-
for i := 0; i < numInhibitingAlerts; i++ {
122+
for i := range numInhibitingAlerts {
123123
alerts = append(alerts, types.Alert{
124124
Alert: model.Alert{
125125
Labels: model.LabelSet{

matcher/parse/lexer_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ func TestLexer_Scan(t *testing.T) {
700700
// error has occurred.
701701
func TestLexer_ScanError(t *testing.T) {
702702
l := lexer{input: "\"hello"}
703-
for i := 0; i < 10; i++ {
703+
for range 10 {
704704
tok, err := l.scan()
705705
require.Equal(t, token{}, tok)
706706
require.EqualError(t, err, "0:6: \"hello: missing end \"")
@@ -738,7 +738,7 @@ func TestLexer_Peek(t *testing.T) {
738738
require.NoError(t, err)
739739
require.Equal(t, expected1, tok)
740740
// Check that peek() returns the second token until the next scan().
741-
for i := 0; i < 10; i++ {
741+
for range 10 {
742742
tok, err = l.peek()
743743
require.NoError(t, err)
744744
require.Equal(t, expected2, tok)
@@ -748,7 +748,7 @@ func TestLexer_Peek(t *testing.T) {
748748
require.NoError(t, err)
749749
require.Equal(t, expected2, tok)
750750
// Should not be able to peek() further tokens.
751-
for i := 0; i < 10; i++ {
751+
for range 10 {
752752
tok, err = l.peek()
753753
require.NoError(t, err)
754754
require.Equal(t, token{}, tok)

notify/incidentio/incidentio_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ func TestIncidentIOPayloadTruncation(t *testing.T) {
325325

326326
// Create alerts with large annotations
327327
var alerts []*types.Alert
328-
for i := 0; i < 10; i++ { // 10 alerts * 100KB = 1MB total in annotations alone
328+
for i := range 10 { // 10 alerts * 100KB = 1MB total in annotations alone
329329
alert := &types.Alert{
330330
Alert: model.Alert{
331331
Labels: model.LabelSet{
@@ -394,7 +394,7 @@ func TestIncidentIOPayloadTruncationWithLabelTruncation(t *testing.T) {
394394

395395
// Create many alerts with many labels to push size over limit even without annotations
396396
var alerts []*types.Alert
397-
for i := 0; i < 100; i++ { // Many alerts
397+
for i := range 100 { // Many alerts
398398
labels := model.LabelSet{
399399
"alertname": model.LabelValue("TestAlert" + string(rune('0'+i%10))),
400400
"severity": "critical",
@@ -403,7 +403,7 @@ func TestIncidentIOPayloadTruncationWithLabelTruncation(t *testing.T) {
403403
}
404404

405405
// Add many extra labels with long values
406-
for j := 0; j < 50; j++ {
406+
for j := range 50 {
407407
labelName := model.LabelName("label_" + string(rune('a'+j%26)) + "_" + string(rune('0'+j/26)))
408408
labelValue := make([]byte, 1024) // 1KB per label value
409409
for k := range labelValue {

provider/mem/mem_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func TestAlertsSubscribePutStarvation(t *testing.T) {
9696

9797
alertsToInsert := []*types.Alert{}
9898
// Exhaust alert channel
99-
for i := 0; i < alertChannelLength+1; i++ {
99+
for i := range alertChannelLength + 1 {
100100
alertsToInsert = append(alertsToInsert, &types.Alert{
101101
Alert: model.Alert{
102102
// Make sure the fingerprints differ
@@ -147,7 +147,7 @@ func TestDeadLock(t *testing.T) {
147147
t.Fatal(err)
148148
}
149149
alertsToInsert := []*types.Alert{}
150-
for i := 0; i < 200+1; i++ {
150+
for i := range 200 + 1 {
151151
alertsToInsert = append(alertsToInsert, &types.Alert{
152152
Alert: model.Alert{
153153
// Make sure the fingerprints differ

silence/silence_bench_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ func benchmarkQuery(b *testing.B, numSilences int) {
276276
lset := model.LabelSet{"aaaa": "AAAA", "bbbb": "BBBB", "cccc": "CCCC"}
277277

278278
// Create silences using Set() to properly populate indices
279-
for i := 0; i < numSilences; i++ {
279+
for i := range numSilences {
280280
id := strconv.Itoa(i)
281281
// Include an offset to avoid optimizations.
282282
patA := "A{4}|" + id
@@ -343,7 +343,7 @@ func benchmarkQueryParallel(b *testing.B, numSilences int) {
343343
lset := model.LabelSet{"aaaa": "AAAA", "bbbb": "BBBB", "cccc": "CCCC"}
344344

345345
// Create silences with pre-compiled matchers
346-
for i := 0; i < numSilences; i++ {
346+
for i := range numSilences {
347347
id := strconv.Itoa(i)
348348
patA := "A{4}|" + id
349349
patB := id

test/cli/acceptance.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func (t *AcceptanceTest) Do(at float64, f func()) {
136136
func (t *AcceptanceTest) AlertmanagerCluster(conf string, size int) *AlertmanagerCluster {
137137
amc := AlertmanagerCluster{}
138138

139-
for i := 0; i < size; i++ {
139+
for range size {
140140
am := &Alertmanager{
141141
t: t,
142142
opts: t.opts,
@@ -353,7 +353,7 @@ func (am *Alertmanager) Start(additionalArg []string) error {
353353
}()
354354

355355
time.Sleep(50 * time.Millisecond)
356-
for i := 0; i < 10; i++ {
356+
for range 10 {
357357
resp, err := http.Get(am.getURL("/"))
358358
if err != nil {
359359
time.Sleep(500 * time.Millisecond)
@@ -380,7 +380,7 @@ func (am *Alertmanager) WaitForCluster(size int) error {
380380
var status general.GetStatusOK
381381

382382
// Poll for 2s
383-
for i := 0; i < 20; i++ {
383+
for range 20 {
384384
status, err := am.clientV2.General.GetStatus(params)
385385
if err != nil {
386386
return err

test/with_api_v2/acceptance.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func (t *AcceptanceTest) Do(at float64, f func()) {
115115
func (t *AcceptanceTest) AlertmanagerCluster(conf string, size int) *AlertmanagerCluster {
116116
amc := AlertmanagerCluster{}
117117

118-
for i := 0; i < size; i++ {
118+
for range size {
119119
am := &Alertmanager{
120120
t: t,
121121
opts: t.opts,
@@ -334,7 +334,7 @@ func (am *Alertmanager) Start(additionalArg []string) error {
334334

335335
time.Sleep(50 * time.Millisecond)
336336
var lastErr error
337-
for i := 0; i < 10; i++ {
337+
for range 10 {
338338
_, lastErr = am.clientV2.General.GetStatus(nil)
339339
if lastErr == nil {
340340
return nil
@@ -352,7 +352,7 @@ func (am *Alertmanager) WaitForCluster(size int) error {
352352
var status *general.GetStatusOK
353353

354354
// Poll for 2s
355-
for i := 0; i < 20; i++ {
355+
for range 20 {
356356
var err error
357357
status, err = am.clientV2.General.GetStatus(params)
358358
if err != nil {

test/with_api_v2/acceptance/send_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ receivers:
286286
func TestResolved(t *testing.T) {
287287
t.Parallel()
288288

289-
for i := 0; i < 2; i++ {
289+
for range 2 {
290290
conf := `
291291
global:
292292
resolve_timeout: 10s

0 commit comments

Comments
 (0)