blob: 1c363260943cb893b2f1924b31268180f19cf0d0 [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{
Krzysztof Grobelny51f0fd52021-12-28 16:32:08 +010049 EXPECT_NO_THROW(sut->commit("Test", Milliseconds{100'000}, commmitValue));
Szymon Dompkef763c9e2021-03-12 09:19:22 +010050}
51
52class TestLogToJournalNumericThrow : public TestLogToJournalNumeric
53{};
54
55INSTANTIATE_TEST_SUITE_P(_, TestLogToJournalNumericThrow, getIncorrectParams());
56
57TEST_P(TestLogToJournalNumericThrow, commitAnActionExpectThrow)
58{
Krzysztof Grobelny51f0fd52021-12-28 16:32:08 +010059 EXPECT_THROW(sut->commit("Test", Milliseconds{100'000}, commmitValue),
Szymon Dompkef763c9e2021-03-12 09:19:22 +010060 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{
Krzysztof Grobelny51f0fd52021-12-28 16:32:08 +010082 EXPECT_NO_THROW(sut->commit("Test", Milliseconds{100'000}, commmitValue));
Szymon Dompkef763c9e2021-03-12 09:19:22 +010083}
84
85class TestLogToRedfishNumericThrow : public TestLogToRedfishNumeric
86{};
87
88INSTANTIATE_TEST_SUITE_P(_, TestLogToRedfishNumericThrow, getIncorrectParams());
89
90TEST_P(TestLogToRedfishNumericThrow, commitExpectToThrow)
91{
Krzysztof Grobelny51f0fd52021-12-28 16:32:08 +010092 EXPECT_THROW(sut->commit("Test", Milliseconds{100'000}, commmitValue),
Szymon Dompkef763c9e2021-03-12 09:19:22 +010093 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{
Krzysztof Grobelny51f0fd52021-12-28 16:32:08 +0100133 EXPECT_NO_THROW(sut->commit("Test", Milliseconds{100'000}, 90.0));
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100134}
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{
Krzysztof Grobelny51f0fd52021-12-28 16:32:08 +0100144 EXPECT_THROW(sut->commit("Test", Milliseconds{100'000}, 90.0),
145 std::runtime_error);
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100146}
147
Szymon Dompkef763c9e2021-03-12 09:19:22 +0100148class TestLogToRedfishDiscrete :
149 public Test,
150 public WithParamInterface<LogParam>
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100151{
152 public:
153 void SetUp() override
154 {
Szymon Dompkef763c9e2021-03-12 09:19:22 +0100155 auto severity = GetParam();
156 sut = std::make_unique<LogToRedfish>(severity);
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100157 }
158
159 std::unique_ptr<LogToRedfish> sut;
160};
161
Szymon Dompkef763c9e2021-03-12 09:19:22 +0100162INSTANTIATE_TEST_SUITE_P(LogToRedfishDiscreteParams, TestLogToRedfishDiscrete,
163 getCorrectParams());
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100164
Szymon Dompkef763c9e2021-03-12 09:19:22 +0100165TEST_P(TestLogToRedfishDiscrete, commitExpectNoThrow)
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100166{
Krzysztof Grobelny51f0fd52021-12-28 16:32:08 +0100167 EXPECT_NO_THROW(sut->commit("Test", Milliseconds{100'000}, 90.0));
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100168}
169
Szymon Dompkef763c9e2021-03-12 09:19:22 +0100170class TestLogToRedfishDiscreteThrow : public TestLogToRedfishDiscrete
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100171{};
172
Szymon Dompkef763c9e2021-03-12 09:19:22 +0100173INSTANTIATE_TEST_SUITE_P(_, TestLogToRedfishDiscreteThrow,
174 getIncorrectParams());
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100175
Szymon Dompkef763c9e2021-03-12 09:19:22 +0100176TEST_P(TestLogToRedfishDiscreteThrow, commitExpectToThrow)
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100177{
Krzysztof Grobelny51f0fd52021-12-28 16:32:08 +0100178 EXPECT_THROW(sut->commit("Test", Milliseconds{100'000}, 90.0),
179 std::runtime_error);
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100180}
181
Szymon Dompkef763c9e2021-03-12 09:19:22 +0100182namespace onChange
183{
184class TestLogToJournalDiscreteOnChange : public Test
185{
186 public:
187 void SetUp() override
188 {
189 sut = std::make_unique<LogToJournal>();
190 }
191
192 std::unique_ptr<LogToJournal> sut;
193};
194
195TEST_F(TestLogToJournalDiscreteOnChange, commitExpectNoThrow)
196{
Krzysztof Grobelny51f0fd52021-12-28 16:32:08 +0100197 EXPECT_NO_THROW(sut->commit("Test", Milliseconds{100'000}, 90.0));
Szymon Dompkef763c9e2021-03-12 09:19:22 +0100198}
199
200class TestLogToRedfishDiscreteOnChange : public Test
201{
202 public:
203 void SetUp() override
204 {
205 sut = std::make_unique<LogToRedfish>();
206 }
207
208 std::unique_ptr<LogToRedfish> sut;
209};
210
211TEST_F(TestLogToRedfishDiscreteOnChange, commitExpectNoThrow)
212{
Krzysztof Grobelny51f0fd52021-12-28 16:32:08 +0100213 EXPECT_NO_THROW(sut->commit("Test", Milliseconds{100'000}, 90.0));
Szymon Dompkef763c9e2021-03-12 09:19:22 +0100214}
215} // namespace onChange
216} // namespace discrete
217
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100218class TestUpdateReport : public Test
219{
220 public:
221 void make(std::vector<std::string> names)
222 {
223 sut = std::make_unique<UpdateReport>(reportManager, std::move(names));
224 }
225
226 NiceMock<ReportManagerMock> reportManager;
227 std::unique_ptr<UpdateReport> sut;
228};
229
230TEST_F(TestUpdateReport, commitWhenReportNameIsEmptyExpectNoReportUpdate)
231{
232 EXPECT_CALL(reportManager, updateReport(_)).Times(0);
233
234 make({});
Krzysztof Grobelny51f0fd52021-12-28 16:32:08 +0100235 sut->commit("Test", Milliseconds{100'000}, 90.0);
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100236}
237
238TEST_F(TestUpdateReport, commitExpectReportUpdate)
239{
240 std::vector<std::string> names = {"Report1", "Report2", "Report3"};
241 for (const auto& name : names)
242 {
243 EXPECT_CALL(reportManager, updateReport(name));
244 }
245
246 make(names);
Krzysztof Grobelny51f0fd52021-12-28 16:32:08 +0100247 sut->commit("Test", Milliseconds{100'000}, 90.0);
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100248}
249
250} // namespace action