@@ -1424,11 +1424,13 @@ func TestAdminClientLogWithoutChannel(t *testing.T) {
1424
1424
t .Fatalf ("Expected admin.Logs() to return a channel, got nil" )
1425
1425
}
1426
1426
1427
- expectedLogs := map [struct {
1427
+ // Define expected logs to validate
1428
+ expectedLogs := []struct {
1428
1429
tag string
1429
1430
message string
1430
- }]bool {
1431
- {"INIT" , "librdkafka" }: false ,
1431
+ found bool
1432
+ }{
1433
+ {"INIT" , "librdkafka" , false },
1432
1434
}
1433
1435
1434
1436
go func () {
@@ -1441,15 +1443,11 @@ func TestAdminClientLogWithoutChannel(t *testing.T) {
1441
1443
1442
1444
t .Log (log .String ())
1443
1445
1444
- for expectedLog , found := range expectedLogs {
1445
- if found {
1446
- continue
1447
- }
1448
- if log .Tag != expectedLog .tag {
1449
- continue
1450
- }
1451
- if strings .Contains (log .Message , expectedLog .message ) {
1452
- expectedLogs [expectedLog ] = true
1446
+ // Check each expected log
1447
+ for i := range expectedLogs {
1448
+ if ! expectedLogs [i ].found && log .Tag == expectedLogs [i ].tag &&
1449
+ strings .Contains (log .Message , expectedLogs [i ].message ) {
1450
+ expectedLogs [i ].found = true
1453
1451
}
1454
1452
}
1455
1453
}
@@ -1458,13 +1456,11 @@ func TestAdminClientLogWithoutChannel(t *testing.T) {
1458
1456
1459
1457
<- time .After (time .Second * 5 )
1460
1458
1461
- for expectedLog , found := range expectedLogs {
1462
- if ! found {
1463
- t .Errorf (
1464
- "Expected to find log with tag `%s' and message containing `%s'," +
1465
- " but didn't find any." ,
1466
- expectedLog .tag ,
1467
- expectedLog .message )
1459
+ // Validate all expected logs were found
1460
+ for _ , expected := range expectedLogs {
1461
+ if ! expected .found {
1462
+ t .Errorf ("Expected to find log with tag `%s' and message containing `%s', but didn't find any." ,
1463
+ expected .tag , expected .message )
1468
1464
}
1469
1465
}
1470
1466
}
0 commit comments