1 #include "remote_logging_tests.hpp"
2 
3 #include <fstream>
4 #include <string>
5 
6 #if __has_include(<filesystem>)
7 #include <filesystem>
8 #elif __has_include(<experimental/filesystem>)
9 #include <experimental/filesystem>
10 namespace std
11 {
12 // splice experimental::filesystem into std
13 namespace filesystem = std::experimental::filesystem;
14 } // namespace std
15 #else
16 #error filesystem not available
17 #endif
18 
19 namespace phosphor
20 {
21 namespace logging
22 {
23 namespace test
24 {
25 
26 std::string getConfig(const char* filePath)
27 {
28     std::fstream stream(filePath, std::fstream::in);
29     std::string line;
30     std::getline(stream, line);
31     return line;
32 }
33 
34 TEST_F(TestRemoteLogging, testOnlyAddress)
35 {
36     config->address("1.1.1.1");
37     EXPECT_EQ(fs::exists(configFilePath.c_str()), false);
38 }
39 
40 TEST_F(TestRemoteLogging, testOnlyPort)
41 {
42     config->port(100);
43     EXPECT_EQ(fs::exists(configFilePath.c_str()), false);
44 }
45 
46 TEST_F(TestRemoteLogging, testGoodConfig)
47 {
48     config->address("1.1.1.1");
49     config->port(100);
50     EXPECT_EQ(getConfig(configFilePath.c_str()), "*.* @@1.1.1.1:100");
51 }
52 
53 TEST_F(TestRemoteLogging, testClearAddress)
54 {
55     config->address("1.1.1.1");
56     config->port(100);
57     EXPECT_EQ(getConfig(configFilePath.c_str()), "*.* @@1.1.1.1:100");
58     config->address("");
59     EXPECT_EQ(fs::exists(configFilePath.c_str()), false);
60 }
61 
62 TEST_F(TestRemoteLogging, testClearPort)
63 {
64     config->address("1.1.1.1");
65     config->port(100);
66     EXPECT_EQ(getConfig(configFilePath.c_str()), "*.* @@1.1.1.1:100");
67     config->port(0);
68     EXPECT_EQ(fs::exists(configFilePath.c_str()), false);
69 }
70 
71 } // namespace test
72 } // namespace logging
73 } // namespace phosphor
74