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