summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDeepak Kodihalli <dkodihal@in.ibm.com>2018-08-30 05:05:46 -0500
committerDeepak Kodihalli <dkodihal@in.ibm.com>2018-08-31 04:41:24 -0500
commit834dcf100f87966bdcb322afda4c23fa4135c021 (patch)
tree54afe01da2c6f29b73f589821e7ad6927c6c1359
parent2ce7b2c37e634da4e38e63f560d04707506746a2 (diff)
downloadphosphor-logging-834dcf100f87966bdcb322afda4c23fa4135c021.zip
phosphor-logging-834dcf100f87966bdcb322afda4c23fa4135c021.tar.gz
phosphor-rsyslog-conf: add unit tests
Add tests related to setting remote server IP address and port. Change-Id: I35ac539a8316d34245ee6b1abcb9f48c1ebe5095 Signed-off-by: Deepak Kodihalli <dkodihal@in.ibm.com>
-rw-r--r--test/Makefile.am21
-rw-r--r--test/remote_logging_test_address.cpp26
-rw-r--r--test/remote_logging_test_port.cpp18
-rw-r--r--test/remote_logging_tests.hpp64
4 files changed, 128 insertions, 1 deletions
diff --git a/test/Makefile.am b/test/Makefile.am
index 68ad467..0db1650 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -5,7 +5,9 @@ TESTS = $(check_PROGRAMS)
check_PROGRAMS = \
elog_errorwrap_test \
serialization_test_path \
- serialization_test_properties
+ serialization_test_properties \
+ remote_logging_test_address \
+ remote_logging_test_port
test_cppflags = \
-Igtest \
@@ -35,6 +37,7 @@ test_ldadd = \
$(top_builddir)/elog-lookup.o \
$(top_builddir)/elog-process-metadata.o
+remote_logging_test_ldadd = $(top_builddir)/phosphor-rsyslog-config/server-conf.o
elog_errorwrap_test_CPPFLAGS = $(test_cppflags)
elog_errorwrap_test_CXXFLAGS = $(test_cxxflags)
@@ -59,3 +62,19 @@ serialization_test_properties_LDADD = $(test_ldadd)
serialization_test_properties_LDFLAGS = \
$(test_ldflags) \
-lstdc++fs
+
+remote_logging_test_address_CPPFLAGS = $(test_cppflags)
+remote_logging_test_address_CXXFLAGS = $(test_cxxflags)
+remote_logging_test_address_SOURCES = remote_logging_test_address.cpp
+remote_logging_test_address_LDADD = $(remote_logging_test_ldadd)
+remote_logging_test_address_LDFLAGS = \
+ $(test_ldflags) \
+ -lstdc++fs
+
+remote_logging_test_port_CPPFLAGS = $(test_cppflags)
+remote_logging_test_port_CXXFLAGS = $(test_cxxflags)
+remote_logging_test_port_SOURCES = remote_logging_test_port.cpp
+remote_logging_test_port_LDADD = $(remote_logging_test_ldadd)
+remote_logging_test_port_LDFLAGS = \
+ $(test_ldflags) \
+ -lstdc++fs
diff --git a/test/remote_logging_test_address.cpp b/test/remote_logging_test_address.cpp
new file mode 100644
index 0000000..1291a2e
--- /dev/null
+++ b/test/remote_logging_test_address.cpp
@@ -0,0 +1,26 @@
+#include "remote_logging_tests.hpp"
+#include "xyz/openbmc_project/Common/error.hpp"
+
+namespace phosphor
+{
+namespace logging
+{
+namespace test
+{
+
+using namespace sdbusplus::xyz::openbmc_project::Common::Error;
+
+TEST_F(TestRemoteLogging, testGoodAddress)
+{
+ config->address("1.1.1.1");
+ EXPECT_EQ(config->address(), "1.1.1.1");
+}
+
+TEST_F(TestRemoteLogging, testBadAddress)
+{
+ EXPECT_THROW(config->address("not_an_IP"), InvalidArgument);
+}
+
+}// namespace test
+}// namespace logging
+}// namespace phosphor
diff --git a/test/remote_logging_test_port.cpp b/test/remote_logging_test_port.cpp
new file mode 100644
index 0000000..a9d3bc3
--- /dev/null
+++ b/test/remote_logging_test_port.cpp
@@ -0,0 +1,18 @@
+#include "remote_logging_tests.hpp"
+
+namespace phosphor
+{
+namespace logging
+{
+namespace test
+{
+
+TEST_F(TestRemoteLogging, testGoodPort)
+{
+ config->port(100);
+ EXPECT_EQ(config->port(), 100);
+}
+
+}// namespace test
+}// namespace logging
+}// namespace phosphor
diff --git a/test/remote_logging_tests.hpp b/test/remote_logging_tests.hpp
new file mode 100644
index 0000000..3606f5a
--- /dev/null
+++ b/test/remote_logging_tests.hpp
@@ -0,0 +1,64 @@
+#include <gtest/gtest.h>
+#include <experimental/filesystem>
+#include <sdbusplus/bus.hpp>
+#include "config.h"
+#include "phosphor-rsyslog-config/server-conf.hpp"
+#include "gmock/gmock.h"
+
+namespace phosphor
+{
+namespace logging
+{
+namespace test
+{
+
+namespace fs = std::experimental::filesystem;
+
+char tmplt[] = "/tmp/logging_test.XXXXXX";
+auto bus = sdbusplus::bus::new_default();
+fs::path dir(fs::path(mkdtemp(tmplt)));
+
+class MockServer : public phosphor::rsyslog_config::Server
+{
+ public:
+ MockServer(sdbusplus::bus::bus& bus,
+ const std::string& path,
+ const char* filePath) :
+ phosphor::rsyslog_config::Server(bus, path, filePath)
+ {
+ }
+
+ MOCK_METHOD0(restart, void());
+};
+
+class TestRemoteLogging : public testing::Test
+{
+ public:
+ TestRemoteLogging()
+ {
+ configFilePath = std::string(dir.c_str()) + "/server.conf";
+ config =
+ new MockServer(bus,
+ BUSPATH_REMOTE_LOGGING_CONFIG,
+ configFilePath.c_str());
+ }
+
+ ~TestRemoteLogging()
+ {
+ delete config;
+ }
+
+ static void TearDownTestCase()
+ {
+ fs::remove_all(dir);
+ }
+
+ MockServer* config;
+ std::string configFilePath;
+};
+
+} // namespace test
+} // namespace logging
+} // namespace phosphor
+
+
OpenPOWER on IntegriCloud