|
@@ -1,4 +1,4 @@
|
|
|
-// Copyright (C) 2014 Internet Systems Consortium, Inc. ("ISC")
|
|
|
+// Copyright (C) 2014-2015 Internet Systems Consortium, Inc. ("ISC")
|
|
|
//
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
@@ -15,6 +15,7 @@
|
|
|
#include <config.h>
|
|
|
#include <exceptions/exceptions.h>
|
|
|
#include <cc/data.h>
|
|
|
+#include <config/module_spec.h>
|
|
|
#include <dhcpsrv/logging.h>
|
|
|
#include <gtest/gtest.h>
|
|
|
#include <log/logger_support.h>
|
|
@@ -45,6 +46,11 @@ class LoggingTest : public ::testing::Test {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
+// Tests that the spec file is valid.
|
|
|
+TEST_F(LoggingTest, basicSpec) {
|
|
|
+ std::string specfile = std::string(TEST_DATA_BUILDDIR) + "/../logging.spec";
|
|
|
+ ASSERT_NO_THROW(isc::config::moduleSpecFromFile(specfile));
|
|
|
+}
|
|
|
|
|
|
// Checks that contructor is able to process specified storage properly
|
|
|
TEST_F(LoggingTest, constructor) {
|
|
@@ -68,7 +74,8 @@ TEST_F(LoggingTest, parsingConsoleOutput) {
|
|
|
" \"name\": \"kea\","
|
|
|
" \"output_options\": ["
|
|
|
" {"
|
|
|
- " \"output\": \"stdout\""
|
|
|
+ " \"output\": \"stdout\","
|
|
|
+ " \"flush\": true"
|
|
|
" }"
|
|
|
" ],"
|
|
|
" \"debuglevel\": 99,"
|
|
@@ -96,6 +103,7 @@ TEST_F(LoggingTest, parsingConsoleOutput) {
|
|
|
|
|
|
ASSERT_EQ(1, storage->getLoggingInfo()[0].destinations_.size());
|
|
|
EXPECT_EQ("stdout" , storage->getLoggingInfo()[0].destinations_[0].output_);
|
|
|
+ EXPECT_TRUE(storage->getLoggingInfo()[0].destinations_[0].flush_);
|
|
|
}
|
|
|
|
|
|
// Checks if the LogConfigParser class is able to transform JSON structures
|
|
@@ -136,6 +144,8 @@ TEST_F(LoggingTest, parsingFile) {
|
|
|
|
|
|
ASSERT_EQ(1, storage->getLoggingInfo()[0].destinations_.size());
|
|
|
EXPECT_EQ("logfile.txt" , storage->getLoggingInfo()[0].destinations_[0].output_);
|
|
|
+ // Default for immediate flush is true
|
|
|
+ EXPECT_TRUE(storage->getLoggingInfo()[0].destinations_[0].flush_);
|
|
|
}
|
|
|
|
|
|
// Checks if the LogConfigParser class is able to transform data structures
|
|
@@ -149,7 +159,8 @@ TEST_F(LoggingTest, multipleLoggers) {
|
|
|
" \"name\": \"kea\","
|
|
|
" \"output_options\": ["
|
|
|
" {"
|
|
|
- " \"output\": \"logfile.txt\""
|
|
|
+ " \"output\": \"logfile.txt\","
|
|
|
+ " \"flush\": true"
|
|
|
" }"
|
|
|
" ],"
|
|
|
" \"severity\": \"INFO\""
|
|
@@ -158,7 +169,8 @@ TEST_F(LoggingTest, multipleLoggers) {
|
|
|
" \"name\": \"wombat\","
|
|
|
" \"output_options\": ["
|
|
|
" {"
|
|
|
- " \"output\": \"logfile2.txt\""
|
|
|
+ " \"output\": \"logfile2.txt\","
|
|
|
+ " \"flush\": false"
|
|
|
" }"
|
|
|
" ],"
|
|
|
" \"severity\": \"DEBUG\","
|
|
@@ -185,12 +197,14 @@ TEST_F(LoggingTest, multipleLoggers) {
|
|
|
EXPECT_EQ(isc::log::INFO, storage->getLoggingInfo()[0].severity_);
|
|
|
ASSERT_EQ(1, storage->getLoggingInfo()[0].destinations_.size());
|
|
|
EXPECT_EQ("logfile.txt" , storage->getLoggingInfo()[0].destinations_[0].output_);
|
|
|
+ EXPECT_TRUE(storage->getLoggingInfo()[0].destinations_[0].flush_);
|
|
|
|
|
|
EXPECT_EQ("wombat", storage->getLoggingInfo()[1].name_);
|
|
|
EXPECT_EQ(99, storage->getLoggingInfo()[1].debuglevel_);
|
|
|
EXPECT_EQ(isc::log::DEBUG, storage->getLoggingInfo()[1].severity_);
|
|
|
ASSERT_EQ(1, storage->getLoggingInfo()[1].destinations_.size());
|
|
|
EXPECT_EQ("logfile2.txt" , storage->getLoggingInfo()[1].destinations_[0].output_);
|
|
|
+ EXPECT_FALSE(storage->getLoggingInfo()[1].destinations_[0].flush_);
|
|
|
}
|
|
|
|
|
|
// Checks if the LogConfigParser class is able to transform data structures
|
|
@@ -233,9 +247,13 @@ TEST_F(LoggingTest, multipleLoggingDestinations) {
|
|
|
EXPECT_EQ(isc::log::INFO, storage->getLoggingInfo()[0].severity_);
|
|
|
ASSERT_EQ(2, storage->getLoggingInfo()[0].destinations_.size());
|
|
|
EXPECT_EQ("logfile.txt" , storage->getLoggingInfo()[0].destinations_[0].output_);
|
|
|
+ EXPECT_TRUE(storage->getLoggingInfo()[0].destinations_[0].flush_);
|
|
|
EXPECT_EQ("stdout" , storage->getLoggingInfo()[0].destinations_[1].output_);
|
|
|
+ EXPECT_TRUE(storage->getLoggingInfo()[0].destinations_[1].flush_);
|
|
|
}
|
|
|
|
|
|
+/// @todo Add tests for malformed logging configuration
|
|
|
+
|
|
|
/// @todo There is no easy way to test applyConfiguration() and defaultLogging().
|
|
|
/// To test them, it would require instrumenting log4cplus to actually fake
|
|
|
/// the logging set up. Alternatively, we could develop set of test suites
|