Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 1 | #include "config.h" |
| 2 | |
| 3 | #include "phosphor-rsyslog-config/server-conf.hpp" |
| 4 | |
Deepak Kodihalli | 834dcf1 | 2018-08-30 05:05:46 -0500 | [diff] [blame] | 5 | #include <sdbusplus/bus.hpp> |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 6 | |
Patrick Williams | 2544b41 | 2022-10-04 08:41:06 -0500 | [diff] [blame] | 7 | #include <filesystem> |
| 8 | |
Deepak Kodihalli | 834dcf1 | 2018-08-30 05:05:46 -0500 | [diff] [blame] | 9 | #include "gmock/gmock.h" |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 10 | #include <gtest/gtest.h> |
Deepak Kodihalli | 834dcf1 | 2018-08-30 05:05:46 -0500 | [diff] [blame] | 11 | |
| 12 | namespace phosphor |
| 13 | { |
| 14 | namespace logging |
| 15 | { |
| 16 | namespace test |
| 17 | { |
| 18 | |
Patrick Williams | 331c485 | 2021-04-16 15:38:59 -0500 | [diff] [blame] | 19 | namespace fs = std::filesystem; |
Deepak Kodihalli | 834dcf1 | 2018-08-30 05:05:46 -0500 | [diff] [blame] | 20 | |
| 21 | char tmplt[] = "/tmp/logging_test.XXXXXX"; |
| 22 | auto bus = sdbusplus::bus::new_default(); |
| 23 | fs::path dir(fs::path(mkdtemp(tmplt))); |
| 24 | |
| 25 | class MockServer : public phosphor::rsyslog_config::Server |
| 26 | { |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 27 | public: |
Patrick Williams | 45e8352 | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 28 | MockServer(sdbusplus::bus_t& bus, const std::string& path, |
Deepak Kodihalli | 834dcf1 | 2018-08-30 05:05:46 -0500 | [diff] [blame] | 29 | const char* filePath) : |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 30 | phosphor::rsyslog_config::Server(bus, path, filePath) |
Patrick Williams | 2544b41 | 2022-10-04 08:41:06 -0500 | [diff] [blame] | 31 | {} |
Deepak Kodihalli | 834dcf1 | 2018-08-30 05:05:46 -0500 | [diff] [blame] | 32 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 33 | MOCK_METHOD0(restart, void()); |
Deepak Kodihalli | 834dcf1 | 2018-08-30 05:05:46 -0500 | [diff] [blame] | 34 | }; |
| 35 | |
| 36 | class TestRemoteLogging : public testing::Test |
| 37 | { |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 38 | public: |
| 39 | TestRemoteLogging() |
| 40 | { |
| 41 | configFilePath = std::string(dir.c_str()) + "/server.conf"; |
| 42 | config = new MockServer(bus, BUSPATH_REMOTE_LOGGING_CONFIG, |
| 43 | configFilePath.c_str()); |
| 44 | } |
Deepak Kodihalli | 834dcf1 | 2018-08-30 05:05:46 -0500 | [diff] [blame] | 45 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 46 | ~TestRemoteLogging() |
| 47 | { |
| 48 | delete config; |
| 49 | } |
Deepak Kodihalli | 834dcf1 | 2018-08-30 05:05:46 -0500 | [diff] [blame] | 50 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 51 | static void TearDownTestCase() |
| 52 | { |
| 53 | fs::remove_all(dir); |
| 54 | } |
Deepak Kodihalli | 834dcf1 | 2018-08-30 05:05:46 -0500 | [diff] [blame] | 55 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 56 | MockServer* config; |
| 57 | std::string configFilePath; |
Deepak Kodihalli | 834dcf1 | 2018-08-30 05:05:46 -0500 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | } // namespace test |
| 61 | } // namespace logging |
| 62 | } // namespace phosphor |