From 358c0e8eb5eb94c575a925727c8eef2f3f10cb47 Mon Sep 17 00:00:00 2001 From: Vikman Fernandez-Castro Date: Tue, 17 Dec 2024 10:05:48 +0100 Subject: [PATCH] test(logcollector): unit test to check event.created format --- .../logcollector/tests/unit/logcollector_test.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/modules/logcollector/tests/unit/logcollector_test.cpp b/src/modules/logcollector/tests/unit/logcollector_test.cpp index 8fe4629d97..6a41439017 100644 --- a/src/modules/logcollector/tests/unit/logcollector_test.cpp +++ b/src/modules/logcollector/tests/unit/logcollector_test.cpp @@ -1,4 +1,5 @@ #include +#include #include "logcollector_mock.hpp" #include #include @@ -7,6 +8,13 @@ using namespace configuration; using namespace logcollector; +bool IsISO8601(const std::string& datetime) { + const std::regex iso8601Regex( + R"(^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$)" + ); + return std::regex_match(datetime, iso8601Regex); +} + TEST(Logcollector, AddReader) { auto logcollector = LogcollectorMock(); auto a = TempFile("/tmp/A.log"); @@ -67,7 +75,7 @@ TEST(Logcollector, SendMessage) { ASSERT_EQ(capturedMessage.type, MessageType::STATELESS); ASSERT_EQ(capturedMessage.data["log"]["file"]["path"], LOCATION); ASSERT_EQ(capturedMessage.data["event"]["original"], LOG); - ASSERT_NE(capturedMessage.data["event"]["created"], nullptr); + ASSERT_TRUE(IsISO8601(capturedMessage.data["event"]["created"])); ASSERT_EQ(capturedMessage.data["event"]["module"], MODULE); ASSERT_EQ(capturedMessage.data["event"]["provider"], PROVIDER); ASSERT_EQ(capturedMessage.metaData, METADATA);