Skip to content

Commit 6736c99

Browse files
committed
sdjournal/TestJournalGetCatalog: fix for new distros
This test assumed the first entry in systemd-journald.service log comes with MESSAGE_ID set. This is not true for modern distros, so the test fails. Add a loop to scan for MESSAGE_ID, and skip if not found. Co-authored-by: Claude Code Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent 4671488 commit 6736c99

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

sdjournal/journal_test.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -453,12 +453,29 @@ func TestJournalGetCatalog(t *testing.T) {
453453
t.Fatalf("Error adding matches to journal: %s", err)
454454
}
455455

456-
if err = waitAndNext(j); err != nil {
457-
t.Fatalf(err.Error())
456+
// Look for an entry with MESSAGE_ID (required for GetCatalog).
457+
found := false
458+
for range 100 {
459+
n, err := j.Next()
460+
if err != nil {
461+
t.Fatalf("Error reading journal: %s", err)
462+
}
463+
if n == 0 {
464+
break
465+
}
466+
467+
// Check if this entry has a MESSAGE_ID
468+
if _, err := j.GetData("MESSAGE_ID"); err == nil {
469+
found = true
470+
break
471+
}
458472
}
459473

460-
catalog, err := j.GetCatalog()
474+
if !found {
475+
t.Skip("No journal entries with MESSAGE_ID found for systemd-journald.service")
476+
}
461477

478+
catalog, err := j.GetCatalog()
462479
if err != nil {
463480
t.Fatalf("Failed to retrieve catalog entry: %s", err)
464481
}

0 commit comments

Comments
 (0)