blob: 7a65fa2dbc6ff9ca67308fcad979d128cc9d8d6b [file] [log] [blame]
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +01001#include "mocks/report_manager_mock.hpp"
2#include "trigger_actions.hpp"
3
4#include <stdexcept>
5
6using namespace testing;
7
8namespace action
9{
Szymon Dompkef763c9e2021-03-12 09:19:22 +010010namespace numeric
11{
12using LogParam = std::tuple<::numeric::Type, double, double>;
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +010013
Szymon Dompkef763c9e2021-03-12 09:19:22 +010014static auto getCorrectParams()
15{
16 return Values(std::make_tuple(::numeric::Type::upperCritical, 91.1, 90),
17 std::make_tuple(::numeric::Type::lowerCritical, 91.2, 90),
18 std::make_tuple(::numeric::Type::upperWarning, 88.5, 90),
19 std::make_tuple(::numeric::Type::lowerWarning, 88.6, 90));
20}
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +010021
Szymon Dompkef763c9e2021-03-12 09:19:22 +010022static auto getIncorrectParams()
23{
24 return Values(
25 std::make_tuple(::numeric::Type::upperCritical, 90.0, 90),
26 std::make_tuple(static_cast<::numeric::Type>(-1), 88.0, 90),
27 std::make_tuple(static_cast<::numeric::Type>(123), 123.0, 90));
28}
29
30class TestLogToJournalNumeric : public Test, public WithParamInterface<LogParam>
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +010031{
32 public:
33 void SetUp() override
34 {
Szymon Dompkef763c9e2021-03-12 09:19:22 +010035 auto [type, threshold, value] = GetParam();
36 sut = std::make_unique<numeric::LogToJournal>(type, threshold);
37 commmitValue = value;
38 }
39
40 std::unique_ptr<numeric::LogToJournal> sut;
41 double commmitValue;
42};
43
44INSTANTIATE_TEST_SUITE_P(LogToJournalNumericParams, TestLogToJournalNumeric,
45 getCorrectParams());
46
47TEST_P(TestLogToJournalNumeric, commitAnActionDoesNotThrow)
48{
49 EXPECT_NO_THROW(sut->commit("Test", 100'000, commmitValue));
50}
51
52class TestLogToJournalNumericThrow : public TestLogToJournalNumeric
53{};
54
55INSTANTIATE_TEST_SUITE_P(_, TestLogToJournalNumericThrow, getIncorrectParams());
56
57TEST_P(TestLogToJournalNumericThrow, commitAnActionExpectThrow)
58{
59 EXPECT_THROW(sut->commit("Test", 100'000, commmitValue),
60 std::runtime_error);
61}
62
63class TestLogToRedfishNumeric : public Test, public WithParamInterface<LogParam>
64{
65 public:
66 void SetUp() override
67 {
68 auto [type, threshold, value] = GetParam();
69 sut = std::make_unique<LogToRedfish>(type, threshold);
70 commmitValue = value;
71 }
72
73 std::unique_ptr<LogToRedfish> sut;
74 double commmitValue;
75};
76
77INSTANTIATE_TEST_SUITE_P(LogToRedfishNumericParams, TestLogToRedfishNumeric,
78 getCorrectParams());
79
80TEST_P(TestLogToRedfishNumeric, commitExpectNoThrow)
81{
82 EXPECT_NO_THROW(sut->commit("Test", 100'000, commmitValue));
83}
84
85class TestLogToRedfishNumericThrow : public TestLogToRedfishNumeric
86{};
87
88INSTANTIATE_TEST_SUITE_P(_, TestLogToRedfishNumericThrow, getIncorrectParams());
89
90TEST_P(TestLogToRedfishNumericThrow, commitExpectToThrow)
91{
92 EXPECT_THROW(sut->commit("Test", 100'000, commmitValue),
93 std::runtime_error);
94}
95
96} // namespace numeric
97
98namespace discrete
99{
100using LogParam = ::discrete::Severity;
101
102static auto getCorrectParams()
103{
104 return Values(::discrete::Severity::critical, ::discrete::Severity::warning,
105 ::discrete::Severity::ok);
106}
107
108static auto getIncorrectParams()
109{
110 return Values(static_cast<::discrete::Severity>(-1),
111 static_cast<::discrete::Severity>(42));
112}
113
114class TestLogToJournalDiscrete :
115 public Test,
116 public WithParamInterface<LogParam>
117{
118 public:
119 void SetUp() override
120 {
121 auto severity = GetParam();
122 sut = std::make_unique<LogToJournal>(severity);
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100123 }
124
125 std::unique_ptr<LogToJournal> sut;
126};
127
Szymon Dompkef763c9e2021-03-12 09:19:22 +0100128INSTANTIATE_TEST_SUITE_P(LogToJournalDiscreteParams, TestLogToJournalDiscrete,
129 getCorrectParams());
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100130
Szymon Dompkef763c9e2021-03-12 09:19:22 +0100131TEST_P(TestLogToJournalDiscrete, commitAnActionDoesNotThrow)
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100132{
133 EXPECT_NO_THROW(sut->commit("Test", 100'000, 90.0));
134}
135
Szymon Dompkef763c9e2021-03-12 09:19:22 +0100136class TestLogToJournalDiscreteThrow : public TestLogToJournalDiscrete
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100137{};
138
Szymon Dompkef763c9e2021-03-12 09:19:22 +0100139INSTANTIATE_TEST_SUITE_P(_, TestLogToJournalDiscreteThrow,
140 getIncorrectParams());
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100141
Szymon Dompkef763c9e2021-03-12 09:19:22 +0100142TEST_P(TestLogToJournalDiscreteThrow, commitAnActionExpectThrow)
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100143{
144 EXPECT_THROW(sut->commit("Test", 100'000, 90.0), std::runtime_error);
145}
146
Szymon Dompkef763c9e2021-03-12 09:19:22 +0100147class TestLogToRedfishDiscrete :
148 public Test,
149 public WithParamInterface<LogParam>
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100150{
151 public:
152 void SetUp() override
153 {
Szymon Dompkef763c9e2021-03-12 09:19:22 +0100154 auto severity = GetParam();
155 sut = std::make_unique<LogToRedfish>(severity);
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100156 }
157
158 std::unique_ptr<LogToRedfish> sut;
159};
160
Szymon Dompkef763c9e2021-03-12 09:19:22 +0100161INSTANTIATE_TEST_SUITE_P(LogToRedfishDiscreteParams, TestLogToRedfishDiscrete,
162 getCorrectParams());
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100163
Szymon Dompkef763c9e2021-03-12 09:19:22 +0100164TEST_P(TestLogToRedfishDiscrete, commitExpectNoThrow)
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100165{
166 EXPECT_NO_THROW(sut->commit("Test", 100'000, 90.0));
167}
168
Szymon Dompkef763c9e2021-03-12 09:19:22 +0100169class TestLogToRedfishDiscreteThrow : public TestLogToRedfishDiscrete
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100170{};
171
Szymon Dompkef763c9e2021-03-12 09:19:22 +0100172INSTANTIATE_TEST_SUITE_P(_, TestLogToRedfishDiscreteThrow,
173 getIncorrectParams());
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100174
Szymon Dompkef763c9e2021-03-12 09:19:22 +0100175TEST_P(TestLogToRedfishDiscreteThrow, commitExpectToThrow)
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100176{
177 EXPECT_THROW(sut->commit("Test", 100'000, 90.0), std::runtime_error);
178}
179
Szymon Dompkef763c9e2021-03-12 09:19:22 +0100180namespace onChange
181{
182class TestLogToJournalDiscreteOnChange : public Test
183{
184 public:
185 void SetUp() override
186 {
187 sut = std::make_unique<LogToJournal>();
188 }
189
190 std::unique_ptr<LogToJournal> sut;
191};
192
193TEST_F(TestLogToJournalDiscreteOnChange, commitExpectNoThrow)
194{
195 EXPECT_NO_THROW(sut->commit("Test", 100'000, 90.0));
196}
197
198class TestLogToRedfishDiscreteOnChange : public Test
199{
200 public:
201 void SetUp() override
202 {
203 sut = std::make_unique<LogToRedfish>();
204 }
205
206 std::unique_ptr<LogToRedfish> sut;
207};
208
209TEST_F(TestLogToRedfishDiscreteOnChange, commitExpectNoThrow)
210{
211 EXPECT_NO_THROW(sut->commit("Test", 100'000, 90.0));
212}
213} // namespace onChange
214} // namespace discrete
215
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100216class TestUpdateReport : public Test
217{
218 public:
219 void make(std::vector<std::string> names)
220 {
221 sut = std::make_unique<UpdateReport>(reportManager, std::move(names));
222 }
223
224 NiceMock<ReportManagerMock> reportManager;
225 std::unique_ptr<UpdateReport> sut;
226};
227
228TEST_F(TestUpdateReport, commitWhenReportNameIsEmptyExpectNoReportUpdate)
229{
230 EXPECT_CALL(reportManager, updateReport(_)).Times(0);
231
232 make({});
233 sut->commit("Test", 100'000, 90.0);
234}
235
236TEST_F(TestUpdateReport, commitExpectReportUpdate)
237{
238 std::vector<std::string> names = {"Report1", "Report2", "Report3"};
239 for (const auto& name : names)
240 {
241 EXPECT_CALL(reportManager, updateReport(name));
242 }
243
244 make(names);
245 sut->commit("Test", 100'000, 90.0);
246}
247
248} // namespace action