Skip to content

Commit

Permalink
test(logcollector): unit test to check event.created format
Browse files Browse the repository at this point in the history
  • Loading branch information
vikman90 committed Dec 17, 2024
1 parent 9ff0be5 commit 358c0e8
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/modules/logcollector/tests/unit/logcollector_test.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <gtest/gtest.h>
#include <regex>
#include "logcollector_mock.hpp"
#include <configuration_parser.hpp>
#include <file_reader.hpp>
Expand All @@ -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");
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 358c0e8

Please sign in to comment.