summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorDeepak Kodihalli <dkodihal@in.ibm.com>2018-08-30 05:38:44 -0500
committerDeepak Kodihalli <dkodihal@in.ibm.com>2018-08-31 04:41:26 -0500
commit5ac1bde129258d906246f5d4ad78e036f03a6e80 (patch)
tree157de05d5168e111c465bebfedf03067839b2836 /test
parent834dcf100f87966bdcb322afda4c23fa4135c021 (diff)
downloadphosphor-logging-5ac1bde129258d906246f5d4ad78e036f03a6e80.zip
phosphor-logging-5ac1bde129258d906246f5d4ad78e036f03a6e80.tar.gz
phosphor-rsyslog-conf: add unit tests
Add tests pertaining to remote logging config file. Change-Id: Idaeac09b5abe91af30dc0eb32664e8af556ecda2 Signed-off-by: Deepak Kodihalli <dkodihal@in.ibm.com>
Diffstat (limited to 'test')
-rw-r--r--test/Makefile.am11
-rw-r--r--test/remote_logging_test_config.cpp58
2 files changed, 68 insertions, 1 deletions
diff --git a/test/Makefile.am b/test/Makefile.am
index 0db1650..30e5472 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -7,7 +7,8 @@ check_PROGRAMS = \
serialization_test_path \
serialization_test_properties \
remote_logging_test_address \
- remote_logging_test_port
+ remote_logging_test_port \
+ remote_logging_test_config
test_cppflags = \
-Igtest \
@@ -78,3 +79,11 @@ remote_logging_test_port_LDADD = $(remote_logging_test_ldadd)
remote_logging_test_port_LDFLAGS = \
$(test_ldflags) \
-lstdc++fs
+
+remote_logging_test_config_CPPFLAGS = $(test_cppflags)
+remote_logging_test_config_CXXFLAGS = $(test_cxxflags)
+remote_logging_test_config_SOURCES = remote_logging_test_config.cpp
+remote_logging_test_config_LDADD = $(remote_logging_test_ldadd)
+remote_logging_test_config_LDFLAGS = \
+ $(test_ldflags) \
+ -lstdc++fs
diff --git a/test/remote_logging_test_config.cpp b/test/remote_logging_test_config.cpp
new file mode 100644
index 0000000..8c3a98a
--- /dev/null
+++ b/test/remote_logging_test_config.cpp
@@ -0,0 +1,58 @@
+#include "remote_logging_tests.hpp"
+#include <fstream>
+
+namespace phosphor
+{
+namespace logging
+{
+namespace test
+{
+
+std::string getConfig(const char* filePath)
+{
+ std::fstream stream(filePath, std::fstream::in);
+ std::string line;
+ getline(stream, line);
+ return line;
+}
+
+TEST_F(TestRemoteLogging, testOnlyAddress)
+{
+ config->address("1.1.1.1");
+ EXPECT_EQ(getConfig(configFilePath.c_str()), "#*.* @@remote-host:port");
+}
+
+TEST_F(TestRemoteLogging, testOnlyPort)
+{
+ config->port(100);
+ EXPECT_EQ(getConfig(configFilePath.c_str()), "#*.* @@remote-host:port");
+}
+
+TEST_F(TestRemoteLogging, testGoodConfig)
+{
+ config->address("1.1.1.1");
+ config->port(100);
+ EXPECT_EQ(getConfig(configFilePath.c_str()), "*.* @@1.1.1.1:100");
+}
+
+TEST_F(TestRemoteLogging, testClearAddress)
+{
+ config->address("1.1.1.1");
+ config->port(100);
+ EXPECT_EQ(getConfig(configFilePath.c_str()), "*.* @@1.1.1.1:100");
+ config->address("");
+ EXPECT_EQ(getConfig(configFilePath.c_str()), "#*.* @@remote-host:port");
+}
+
+TEST_F(TestRemoteLogging, testClearPort)
+{
+ config->address("1.1.1.1");
+ config->port(100);
+ EXPECT_EQ(getConfig(configFilePath.c_str()), "*.* @@1.1.1.1:100");
+ config->port(0);
+ EXPECT_EQ(getConfig(configFilePath.c_str()), "#*.* @@remote-host:port");
+}
+
+}// namespace test
+}// namespace logging
+}// namespace phosphor
OpenPOWER on IntegriCloud