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 | |
Patrick Williams | 331c485 | 2021-04-16 15:38:59 -0500 | [diff] [blame] | 5 | #include <filesystem> |
Deepak Kodihalli | 834dcf1 | 2018-08-30 05:05:46 -0500 | [diff] [blame] | 6 | #include <sdbusplus/bus.hpp> |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 7 | |
Deepak Kodihalli | 834dcf1 | 2018-08-30 05:05:46 -0500 | [diff] [blame] | 8 | #include "gmock/gmock.h" |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 9 | #include <gtest/gtest.h> |
Deepak Kodihalli | 834dcf1 | 2018-08-30 05:05:46 -0500 | [diff] [blame] | 10 | |
| 11 | namespace phosphor |
| 12 | { |
| 13 | namespace logging |
| 14 | { |
| 15 | namespace test |
| 16 | { |
| 17 | |
Patrick Williams | 331c485 | 2021-04-16 15:38:59 -0500 | [diff] [blame] | 18 | namespace fs = std::filesystem; |
Deepak Kodihalli | 834dcf1 | 2018-08-30 05:05:46 -0500 | [diff] [blame] | 19 | |
| 20 | char tmplt[] = "/tmp/logging_test.XXXXXX"; |
| 21 | auto bus = sdbusplus::bus::new_default(); |
| 22 | fs::path dir(fs::path(mkdtemp(tmplt))); |
| 23 | |
| 24 | class MockServer : public phosphor::rsyslog_config::Server |
| 25 | { |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 26 | public: |
Patrick Williams | 45e8352 | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 27 | MockServer(sdbusplus::bus_t& bus, const std::string& path, |
Deepak Kodihalli | 834dcf1 | 2018-08-30 05:05:46 -0500 | [diff] [blame] | 28 | const char* filePath) : |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 29 | phosphor::rsyslog_config::Server(bus, path, filePath) |
| 30 | { |
| 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 |