INNER CODE UNIT · Go
TestReadLastMatchingLogRecord
oracle/oracle-db-appdev-monitoring · alertlog/alertlog_test.go:103
func TestReadLastMatchingLogRecord(t *testing.T) {
t.Run("shared log returns latest record for matching database", func(t *testing.T) {
logPath := filepath.Join(t.TempDir(), "alert.log")
content := "" +
"{\"timestamp\":\"2026-03-13T12:00:00.000Z\",\"database\":\"db1\",\"moduleId\":\"\",\"ecid\":\"\",\"message\":\"db1-old\"}\n" +
"{\"timestamp\":\"2026-03-13T12:05:00.000Z\",\"database\":\"db2\",\"moduleId\":\"\",\"ecid\":\"\",\"message\":\"db2-newest\"}\n" +
"{\"timestamp\":\"2026-03-13T12:03:00.000Z\",\"database\":\"db1\",\"moduleId\":\"\",\"ecid\":\"\",\"message\":\"db1-newest\"}\n"
if err := os.WriteFile(logPath, []byte(content), 0600); err != nil {
t.Fatalf("write log: %v", err)
}
record, err := readLastMatchingLogRecord(logPath, "db1", false)
if err != nil {
t.Fatalf("read last matching log record: %v", err)
}
if record.Timestamp != "2026-03-13T12:03:00.000Z" {
t.Fatalf("expected latest db1 timestamp, got %q", record.Timestamp)
}