Add test to ensure config loading impacts runtime log level

pull/1061/head
Stephen Shelton 4 years ago
parent 43998f97c8
commit 9a65f19bb0
No known key found for this signature in database
GPG Key ID: EE4BADACCE8B631C

@ -1,5 +1,7 @@
#include <gtest/gtest.h>
#include <util/logging/loglevel.hpp>
#include <util/logging/logger.hpp>
#include <config/config.hpp>
using TestString = std::string;
@ -61,3 +63,36 @@ TEST_F(LogLevelTest, TestLogLevelToString)
EXPECT_EQ("???", LogLevelToString(llarp::eLogNone));
}
TEST_F(LogLevelTest, TestLoggingConfigSideEffects)
{
// restore original runtime level when we're done
llarp::LogContext& logContext = llarp::LogContext::Instance();
auto original = logContext.runtimeLevel;
// LoggingConfig::fromSection updates the runtime level as it reads in conf
// values, so feed it values and ensure that the runtime level is updated
// appropriately
llarp::LoggingConfig config;
config.fromSection("level", "Trace");
EXPECT_EQ(llarp::eLogTrace, logContext.runtimeLevel);
config.fromSection("level", "Debug");
EXPECT_EQ(llarp::eLogDebug, logContext.runtimeLevel);
config.fromSection("level", "Info");
EXPECT_EQ(llarp::eLogInfo, logContext.runtimeLevel);
config.fromSection("level", "Warn");
EXPECT_EQ(llarp::eLogWarn, logContext.runtimeLevel);
config.fromSection("level", "Error");
EXPECT_EQ(llarp::eLogError, logContext.runtimeLevel);
config.fromSection("level", "None");
EXPECT_EQ(llarp::eLogNone, logContext.runtimeLevel);
SetLogLevel(original);
}

Loading…
Cancel
Save