blob: a4c62079f1f8419edde1f769731ef081f9e0a161 [file] [log] [blame]
Deepak Kodihalli5ac1bde2018-08-30 05:38:44 -05001#include "remote_logging_tests.hpp"
Patrick Venturef18bf832018-10-26 18:14:00 -07002
Deepak Kodihalli5ac1bde2018-08-30 05:38:44 -05003#include <fstream>
Patrick Venture30047bf2018-11-01 18:52:15 -07004#include <string>
Deepak Kodihalli5ac1bde2018-08-30 05:38:44 -05005
6namespace phosphor
7{
8namespace logging
9{
10namespace test
11{
12
13std::string getConfig(const char* filePath)
14{
15 std::fstream stream(filePath, std::fstream::in);
16 std::string line;
Patrick Venture30047bf2018-11-01 18:52:15 -070017 std::getline(stream, line);
Deepak Kodihalli5ac1bde2018-08-30 05:38:44 -050018 return line;
19}
20
21TEST_F(TestRemoteLogging, testOnlyAddress)
22{
23 config->address("1.1.1.1");
24 EXPECT_EQ(getConfig(configFilePath.c_str()), "#*.* @@remote-host:port");
25}
26
27TEST_F(TestRemoteLogging, testOnlyPort)
28{
29 config->port(100);
30 EXPECT_EQ(getConfig(configFilePath.c_str()), "#*.* @@remote-host:port");
31}
32
33TEST_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
40TEST_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("");
46 EXPECT_EQ(getConfig(configFilePath.c_str()), "#*.* @@remote-host:port");
47}
48
49TEST_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);
55 EXPECT_EQ(getConfig(configFilePath.c_str()), "#*.* @@remote-host:port");
56}
57
Patrick Venturef18bf832018-10-26 18:14:00 -070058} // namespace test
59} // namespace logging
60} // namespace phosphor