Deepak Kodihalli | 5ac1bde | 2018-08-30 05:38:44 -0500 | [diff] [blame] | 1 | #include "remote_logging_tests.hpp" |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 2 | |
Deepak Kodihalli | 5ac1bde | 2018-08-30 05:38:44 -0500 | [diff] [blame] | 3 | #include <fstream> |
| 4 | |
| 5 | namespace phosphor |
| 6 | { |
| 7 | namespace logging |
| 8 | { |
| 9 | namespace test |
| 10 | { |
| 11 | |
| 12 | std::string getConfig(const char* filePath) |
| 13 | { |
| 14 | std::fstream stream(filePath, std::fstream::in); |
| 15 | std::string line; |
| 16 | getline(stream, line); |
| 17 | return line; |
| 18 | } |
| 19 | |
| 20 | TEST_F(TestRemoteLogging, testOnlyAddress) |
| 21 | { |
| 22 | config->address("1.1.1.1"); |
| 23 | EXPECT_EQ(getConfig(configFilePath.c_str()), "#*.* @@remote-host:port"); |
| 24 | } |
| 25 | |
| 26 | TEST_F(TestRemoteLogging, testOnlyPort) |
| 27 | { |
| 28 | config->port(100); |
| 29 | EXPECT_EQ(getConfig(configFilePath.c_str()), "#*.* @@remote-host:port"); |
| 30 | } |
| 31 | |
| 32 | TEST_F(TestRemoteLogging, testGoodConfig) |
| 33 | { |
| 34 | config->address("1.1.1.1"); |
| 35 | config->port(100); |
| 36 | EXPECT_EQ(getConfig(configFilePath.c_str()), "*.* @@1.1.1.1:100"); |
| 37 | } |
| 38 | |
| 39 | TEST_F(TestRemoteLogging, testClearAddress) |
| 40 | { |
| 41 | config->address("1.1.1.1"); |
| 42 | config->port(100); |
| 43 | EXPECT_EQ(getConfig(configFilePath.c_str()), "*.* @@1.1.1.1:100"); |
| 44 | config->address(""); |
| 45 | EXPECT_EQ(getConfig(configFilePath.c_str()), "#*.* @@remote-host:port"); |
| 46 | } |
| 47 | |
| 48 | TEST_F(TestRemoteLogging, testClearPort) |
| 49 | { |
| 50 | config->address("1.1.1.1"); |
| 51 | config->port(100); |
| 52 | EXPECT_EQ(getConfig(configFilePath.c_str()), "*.* @@1.1.1.1:100"); |
| 53 | config->port(0); |
| 54 | EXPECT_EQ(getConfig(configFilePath.c_str()), "#*.* @@remote-host:port"); |
| 55 | } |
| 56 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 57 | } // namespace test |
| 58 | } // namespace logging |
| 59 | } // namespace phosphor |