blob: d3e36b897d258ece592ce77d85da3203653bbb39 [file] [log] [blame]
Krzysztof Grobelnye6d48872022-02-08 13:41:30 +01001#include "dbus_environment.hpp"
2#include "messages/update_report_ind.hpp"
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +01003#include "trigger_actions.hpp"
Krzysztof Grobelnye6d48872022-02-08 13:41:30 +01004#include "utils/messanger.hpp"
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +01005
6#include <stdexcept>
7
Krzysztof Grobelnye6d48872022-02-08 13:41:30 +01008#include <gmock/gmock.h>
9
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +010010using namespace testing;
11
12namespace action
13{
Szymon Dompkef763c9e2021-03-12 09:19:22 +010014namespace numeric
15{
16using LogParam = std::tuple<::numeric::Type, double, double>;
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +010017
Szymon Dompkef763c9e2021-03-12 09:19:22 +010018static auto getCorrectParams()
19{
20 return Values(std::make_tuple(::numeric::Type::upperCritical, 91.1, 90),
21 std::make_tuple(::numeric::Type::lowerCritical, 91.2, 90),
22 std::make_tuple(::numeric::Type::upperWarning, 88.5, 90),
23 std::make_tuple(::numeric::Type::lowerWarning, 88.6, 90));
24}
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +010025
Szymon Dompkef763c9e2021-03-12 09:19:22 +010026static auto getIncorrectParams()
27{
28 return Values(
29 std::make_tuple(::numeric::Type::upperCritical, 90.0, 90),
30 std::make_tuple(static_cast<::numeric::Type>(-1), 88.0, 90),
31 std::make_tuple(static_cast<::numeric::Type>(123), 123.0, 90));
32}
33
34class TestLogToJournalNumeric : public Test, public WithParamInterface<LogParam>
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +010035{
36 public:
37 void SetUp() override
38 {
Szymon Dompkef763c9e2021-03-12 09:19:22 +010039 auto [type, threshold, value] = GetParam();
40 sut = std::make_unique<numeric::LogToJournal>(type, threshold);
41 commmitValue = value;
42 }
43
44 std::unique_ptr<numeric::LogToJournal> sut;
45 double commmitValue;
46};
47
48INSTANTIATE_TEST_SUITE_P(LogToJournalNumericParams, TestLogToJournalNumeric,
49 getCorrectParams());
50
51TEST_P(TestLogToJournalNumeric, commitAnActionDoesNotThrow)
52{
Krzysztof Grobelny51f0fd52021-12-28 16:32:08 +010053 EXPECT_NO_THROW(sut->commit("Test", Milliseconds{100'000}, commmitValue));
Szymon Dompkef763c9e2021-03-12 09:19:22 +010054}
55
56class TestLogToJournalNumericThrow : public TestLogToJournalNumeric
57{};
58
59INSTANTIATE_TEST_SUITE_P(_, TestLogToJournalNumericThrow, getIncorrectParams());
60
61TEST_P(TestLogToJournalNumericThrow, commitAnActionExpectThrow)
62{
Krzysztof Grobelny51f0fd52021-12-28 16:32:08 +010063 EXPECT_THROW(sut->commit("Test", Milliseconds{100'000}, commmitValue),
Szymon Dompkef763c9e2021-03-12 09:19:22 +010064 std::runtime_error);
65}
66
67class TestLogToRedfishNumeric : public Test, public WithParamInterface<LogParam>
68{
69 public:
70 void SetUp() override
71 {
72 auto [type, threshold, value] = GetParam();
73 sut = std::make_unique<LogToRedfish>(type, threshold);
74 commmitValue = value;
75 }
76
77 std::unique_ptr<LogToRedfish> sut;
78 double commmitValue;
79};
80
81INSTANTIATE_TEST_SUITE_P(LogToRedfishNumericParams, TestLogToRedfishNumeric,
82 getCorrectParams());
83
84TEST_P(TestLogToRedfishNumeric, commitExpectNoThrow)
85{
Krzysztof Grobelny51f0fd52021-12-28 16:32:08 +010086 EXPECT_NO_THROW(sut->commit("Test", Milliseconds{100'000}, commmitValue));
Szymon Dompkef763c9e2021-03-12 09:19:22 +010087}
88
89class TestLogToRedfishNumericThrow : public TestLogToRedfishNumeric
90{};
91
92INSTANTIATE_TEST_SUITE_P(_, TestLogToRedfishNumericThrow, getIncorrectParams());
93
94TEST_P(TestLogToRedfishNumericThrow, commitExpectToThrow)
95{
Krzysztof Grobelny51f0fd52021-12-28 16:32:08 +010096 EXPECT_THROW(sut->commit("Test", Milliseconds{100'000}, commmitValue),
Szymon Dompkef763c9e2021-03-12 09:19:22 +010097 std::runtime_error);
98}
99
100} // namespace numeric
101
102namespace discrete
103{
104using LogParam = ::discrete::Severity;
105
106static auto getCorrectParams()
107{
108 return Values(::discrete::Severity::critical, ::discrete::Severity::warning,
109 ::discrete::Severity::ok);
110}
111
112static auto getIncorrectParams()
113{
114 return Values(static_cast<::discrete::Severity>(-1),
115 static_cast<::discrete::Severity>(42));
116}
117
118class TestLogToJournalDiscrete :
119 public Test,
120 public WithParamInterface<LogParam>
121{
122 public:
123 void SetUp() override
124 {
125 auto severity = GetParam();
126 sut = std::make_unique<LogToJournal>(severity);
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100127 }
128
129 std::unique_ptr<LogToJournal> sut;
130};
131
Szymon Dompkef763c9e2021-03-12 09:19:22 +0100132INSTANTIATE_TEST_SUITE_P(LogToJournalDiscreteParams, TestLogToJournalDiscrete,
133 getCorrectParams());
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100134
Szymon Dompkef763c9e2021-03-12 09:19:22 +0100135TEST_P(TestLogToJournalDiscrete, commitAnActionDoesNotThrow)
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100136{
Krzysztof Grobelny51f0fd52021-12-28 16:32:08 +0100137 EXPECT_NO_THROW(sut->commit("Test", Milliseconds{100'000}, 90.0));
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100138}
139
Szymon Dompkef763c9e2021-03-12 09:19:22 +0100140class TestLogToJournalDiscreteThrow : public TestLogToJournalDiscrete
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100141{};
142
Szymon Dompkef763c9e2021-03-12 09:19:22 +0100143INSTANTIATE_TEST_SUITE_P(_, TestLogToJournalDiscreteThrow,
144 getIncorrectParams());
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100145
Szymon Dompkef763c9e2021-03-12 09:19:22 +0100146TEST_P(TestLogToJournalDiscreteThrow, commitAnActionExpectThrow)
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100147{
Krzysztof Grobelny51f0fd52021-12-28 16:32:08 +0100148 EXPECT_THROW(sut->commit("Test", Milliseconds{100'000}, 90.0),
149 std::runtime_error);
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100150}
151
Szymon Dompkef763c9e2021-03-12 09:19:22 +0100152class TestLogToRedfishDiscrete :
153 public Test,
154 public WithParamInterface<LogParam>
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100155{
156 public:
157 void SetUp() override
158 {
Szymon Dompkef763c9e2021-03-12 09:19:22 +0100159 auto severity = GetParam();
160 sut = std::make_unique<LogToRedfish>(severity);
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100161 }
162
163 std::unique_ptr<LogToRedfish> sut;
164};
165
Szymon Dompkef763c9e2021-03-12 09:19:22 +0100166INSTANTIATE_TEST_SUITE_P(LogToRedfishDiscreteParams, TestLogToRedfishDiscrete,
167 getCorrectParams());
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100168
Szymon Dompkef763c9e2021-03-12 09:19:22 +0100169TEST_P(TestLogToRedfishDiscrete, commitExpectNoThrow)
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100170{
Krzysztof Grobelny51f0fd52021-12-28 16:32:08 +0100171 EXPECT_NO_THROW(sut->commit("Test", Milliseconds{100'000}, 90.0));
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100172}
173
Szymon Dompkef763c9e2021-03-12 09:19:22 +0100174class TestLogToRedfishDiscreteThrow : public TestLogToRedfishDiscrete
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100175{};
176
Szymon Dompkef763c9e2021-03-12 09:19:22 +0100177INSTANTIATE_TEST_SUITE_P(_, TestLogToRedfishDiscreteThrow,
178 getIncorrectParams());
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100179
Szymon Dompkef763c9e2021-03-12 09:19:22 +0100180TEST_P(TestLogToRedfishDiscreteThrow, commitExpectToThrow)
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100181{
Krzysztof Grobelny51f0fd52021-12-28 16:32:08 +0100182 EXPECT_THROW(sut->commit("Test", Milliseconds{100'000}, 90.0),
183 std::runtime_error);
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100184}
185
Szymon Dompkef763c9e2021-03-12 09:19:22 +0100186namespace onChange
187{
188class TestLogToJournalDiscreteOnChange : public Test
189{
190 public:
191 void SetUp() override
192 {
193 sut = std::make_unique<LogToJournal>();
194 }
195
196 std::unique_ptr<LogToJournal> sut;
197};
198
199TEST_F(TestLogToJournalDiscreteOnChange, commitExpectNoThrow)
200{
Krzysztof Grobelny51f0fd52021-12-28 16:32:08 +0100201 EXPECT_NO_THROW(sut->commit("Test", Milliseconds{100'000}, 90.0));
Szymon Dompkef763c9e2021-03-12 09:19:22 +0100202}
203
204class TestLogToRedfishDiscreteOnChange : public Test
205{
206 public:
207 void SetUp() override
208 {
209 sut = std::make_unique<LogToRedfish>();
210 }
211
212 std::unique_ptr<LogToRedfish> sut;
213};
214
215TEST_F(TestLogToRedfishDiscreteOnChange, commitExpectNoThrow)
216{
Krzysztof Grobelny51f0fd52021-12-28 16:32:08 +0100217 EXPECT_NO_THROW(sut->commit("Test", Milliseconds{100'000}, 90.0));
Szymon Dompkef763c9e2021-03-12 09:19:22 +0100218}
219} // namespace onChange
220} // namespace discrete
221
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100222class TestUpdateReport : public Test
223{
224 public:
Krzysztof Grobelnye6d48872022-02-08 13:41:30 +0100225 TestUpdateReport() : messanger(DbusEnvironment::getIoc())
226 {}
227
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100228 void make(std::vector<std::string> names)
229 {
Krzysztof Grobelnye6d48872022-02-08 13:41:30 +0100230 messanger.on_receive<messages::UpdateReportInd>(
231 [this](const auto& msg) { updateReport.Call(msg); });
232
Szymon Dompke94f71c52021-12-10 07:16:33 +0100233 sut = std::make_unique<UpdateReport>(
Krzysztof Grobelnye6d48872022-02-08 13:41:30 +0100234 DbusEnvironment::getIoc(),
Szymon Dompke94f71c52021-12-10 07:16:33 +0100235 std::make_shared<std::vector<std::string>>(std::move(names)));
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100236 }
237
Krzysztof Grobelnye6d48872022-02-08 13:41:30 +0100238 utils::Messanger messanger;
239 NiceMock<MockFunction<void(const messages::UpdateReportInd&)>> updateReport;
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100240 std::unique_ptr<UpdateReport> sut;
241};
242
243TEST_F(TestUpdateReport, commitWhenReportNameIsEmptyExpectNoReportUpdate)
244{
Krzysztof Grobelnye6d48872022-02-08 13:41:30 +0100245 EXPECT_CALL(updateReport, Call(_)).Times(0);
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100246
247 make({});
Krzysztof Grobelny51f0fd52021-12-28 16:32:08 +0100248 sut->commit("Test", Milliseconds{100'000}, 90.0);
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100249}
250
251TEST_F(TestUpdateReport, commitExpectReportUpdate)
252{
253 std::vector<std::string> names = {"Report1", "Report2", "Report3"};
Krzysztof Grobelnye6d48872022-02-08 13:41:30 +0100254 EXPECT_CALL(updateReport,
255 Call(FieldsAre(UnorderedElementsAreArray(names))));
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100256
257 make(names);
Krzysztof Grobelny51f0fd52021-12-28 16:32:08 +0100258 sut->commit("Test", Milliseconds{100'000}, 90.0);
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100259}
260
261} // namespace action