test(tests): fixed broken tests

This commit is contained in:
2025-03-26 10:06:10 -04:00
parent 9395b52089
commit 7193d3a6ac
8 changed files with 18 additions and 165 deletions

View File

@@ -7,9 +7,12 @@
#include <sstream>
#include <regex>
#include <source_location>
#include "config.h"
#include <chrono>
#include "quill/LogMacros.h"
std::string TEST_CONFIG = std::string(getenv("MESON_SOURCE_ROOT")) + "/tests/testsConfig.yaml";
std::string getLastLine(const std::string& filename) {
std::ifstream file(filename);
std::string line, lastLine;
@@ -38,6 +41,7 @@ std::string stripTimestamps(const std::string& logLine) {
class probeTest : public ::testing::Test {};
TEST_F(probeTest, DefaultConstructorTest) {
Config::getInstance().loadConfig(TEST_CONFIG);
EXPECT_NO_THROW(Probe::LogManager::getInstance());
}
@@ -50,20 +54,23 @@ TEST_F(probeTest, waitTest) {
}
TEST_F(probeTest, getLoggerTest) {
Config::getInstance().loadConfig(TEST_CONFIG);
Probe::LogManager& logManager = Probe::LogManager::getInstance();
std::string loggerName = "log";
quill::Logger* logger = logManager.getLogger(loggerName);
const std::string loggerName = "testLog";
const std::string filename = "test.log";
quill::Logger* logger = logManager.newFileLogger(filename, loggerName);
EXPECT_NE(logger, nullptr);
LOG_INFO(logger, "This is a test message");
// Wait for the log to be written by calling getLastLine until it is non empty
std::string lastLine;
while (lastLine.empty()) {
lastLine = getLastLine("4DSSE.log");
lastLine = getLastLine("test.log");
}
EXPECT_EQ(stripTimestamps(lastLine), "This is a test message");
}
TEST_F(probeTest, newFileLoggerTest) {
Config::getInstance().loadConfig(TEST_CONFIG);
Probe::LogManager& logManager = Probe::LogManager::getInstance();
const std::string loggerName = "newLog";
const std::string filename = "newLog.log";
@@ -79,10 +86,12 @@ TEST_F(probeTest, newFileLoggerTest) {
}
TEST_F(probeTest, getLoggerNames) {
Config::getInstance().loadConfig(TEST_CONFIG);
Probe::LogManager& logManager = Probe::LogManager::getInstance();
std::vector<std::string> loggerNames = logManager.getLoggerNames();
EXPECT_EQ(loggerNames.size(), 3);
EXPECT_EQ(loggerNames.size(), 4);
EXPECT_EQ(loggerNames.at(0), "log");
EXPECT_EQ(loggerNames.at(1), "newLog");
EXPECT_EQ(loggerNames.at(2), "stdout");
EXPECT_EQ(loggerNames.at(3), "testLog");
}