Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 1 | #include "dbus_environment.hpp" |
| 2 | #include "messages/update_report_ind.hpp" |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 3 | #include "trigger_actions.hpp" |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 4 | #include "utils/messanger.hpp" |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 5 | |
| 6 | #include <stdexcept> |
| 7 | |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 8 | #include <gmock/gmock.h> |
| 9 | |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 10 | using namespace testing; |
| 11 | |
| 12 | namespace action |
| 13 | { |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 14 | namespace numeric |
| 15 | { |
| 16 | using LogParam = std::tuple<::numeric::Type, double, double>; |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 17 | |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 18 | static 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, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 25 | |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 26 | static 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 | |
| 34 | class TestLogToJournalNumeric : public Test, public WithParamInterface<LogParam> |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 35 | { |
| 36 | public: |
| 37 | void SetUp() override |
| 38 | { |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 39 | 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 | |
| 48 | INSTANTIATE_TEST_SUITE_P(LogToJournalNumericParams, TestLogToJournalNumeric, |
| 49 | getCorrectParams()); |
| 50 | |
| 51 | TEST_P(TestLogToJournalNumeric, commitAnActionDoesNotThrow) |
| 52 | { |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame] | 53 | EXPECT_NO_THROW(sut->commit("Test", Milliseconds{100'000}, commmitValue)); |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | class TestLogToJournalNumericThrow : public TestLogToJournalNumeric |
| 57 | {}; |
| 58 | |
| 59 | INSTANTIATE_TEST_SUITE_P(_, TestLogToJournalNumericThrow, getIncorrectParams()); |
| 60 | |
| 61 | TEST_P(TestLogToJournalNumericThrow, commitAnActionExpectThrow) |
| 62 | { |
Szymon Dompke | f670b02 | 2022-03-16 19:21:11 +0100 | [diff] [blame] | 63 | EXPECT_ANY_THROW(sut->commit("Test", Milliseconds{100'000}, commmitValue)); |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | class TestLogToRedfishNumeric : public Test, public WithParamInterface<LogParam> |
| 67 | { |
| 68 | public: |
| 69 | void SetUp() override |
| 70 | { |
| 71 | auto [type, threshold, value] = GetParam(); |
| 72 | sut = std::make_unique<LogToRedfish>(type, threshold); |
| 73 | commmitValue = value; |
| 74 | } |
| 75 | |
| 76 | std::unique_ptr<LogToRedfish> sut; |
| 77 | double commmitValue; |
| 78 | }; |
| 79 | |
| 80 | INSTANTIATE_TEST_SUITE_P(LogToRedfishNumericParams, TestLogToRedfishNumeric, |
| 81 | getCorrectParams()); |
| 82 | |
| 83 | TEST_P(TestLogToRedfishNumeric, commitExpectNoThrow) |
| 84 | { |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame] | 85 | EXPECT_NO_THROW(sut->commit("Test", Milliseconds{100'000}, commmitValue)); |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | class TestLogToRedfishNumericThrow : public TestLogToRedfishNumeric |
| 89 | {}; |
| 90 | |
| 91 | INSTANTIATE_TEST_SUITE_P(_, TestLogToRedfishNumericThrow, getIncorrectParams()); |
| 92 | |
| 93 | TEST_P(TestLogToRedfishNumericThrow, commitExpectToThrow) |
| 94 | { |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame] | 95 | EXPECT_THROW(sut->commit("Test", Milliseconds{100'000}, commmitValue), |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 96 | std::runtime_error); |
| 97 | } |
| 98 | |
| 99 | } // namespace numeric |
| 100 | |
| 101 | namespace discrete |
| 102 | { |
| 103 | using LogParam = ::discrete::Severity; |
| 104 | |
| 105 | static auto getCorrectParams() |
| 106 | { |
| 107 | return Values(::discrete::Severity::critical, ::discrete::Severity::warning, |
| 108 | ::discrete::Severity::ok); |
| 109 | } |
| 110 | |
| 111 | static auto getIncorrectParams() |
| 112 | { |
| 113 | return Values(static_cast<::discrete::Severity>(-1), |
| 114 | static_cast<::discrete::Severity>(42)); |
| 115 | } |
| 116 | |
| 117 | class TestLogToJournalDiscrete : |
| 118 | public Test, |
| 119 | public WithParamInterface<LogParam> |
| 120 | { |
| 121 | public: |
| 122 | void SetUp() override |
| 123 | { |
| 124 | auto severity = GetParam(); |
| 125 | sut = std::make_unique<LogToJournal>(severity); |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | std::unique_ptr<LogToJournal> sut; |
| 129 | }; |
| 130 | |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 131 | INSTANTIATE_TEST_SUITE_P(LogToJournalDiscreteParams, TestLogToJournalDiscrete, |
| 132 | getCorrectParams()); |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 133 | |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 134 | TEST_P(TestLogToJournalDiscrete, commitAnActionDoesNotThrow) |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 135 | { |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame] | 136 | EXPECT_NO_THROW(sut->commit("Test", Milliseconds{100'000}, 90.0)); |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 137 | } |
| 138 | |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 139 | class TestLogToJournalDiscreteThrow : public TestLogToJournalDiscrete |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 140 | {}; |
| 141 | |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 142 | INSTANTIATE_TEST_SUITE_P(_, TestLogToJournalDiscreteThrow, |
| 143 | getIncorrectParams()); |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 144 | |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 145 | TEST_P(TestLogToJournalDiscreteThrow, commitAnActionExpectThrow) |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 146 | { |
Szymon Dompke | f670b02 | 2022-03-16 19:21:11 +0100 | [diff] [blame] | 147 | EXPECT_ANY_THROW(sut->commit("Test", Milliseconds{100'000}, 90.0)); |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 148 | } |
| 149 | |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 150 | class TestLogToRedfishDiscrete : |
| 151 | public Test, |
| 152 | public WithParamInterface<LogParam> |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 153 | { |
| 154 | public: |
| 155 | void SetUp() override |
| 156 | { |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 157 | auto severity = GetParam(); |
| 158 | sut = std::make_unique<LogToRedfish>(severity); |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | std::unique_ptr<LogToRedfish> sut; |
| 162 | }; |
| 163 | |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 164 | INSTANTIATE_TEST_SUITE_P(LogToRedfishDiscreteParams, TestLogToRedfishDiscrete, |
| 165 | getCorrectParams()); |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 166 | |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 167 | TEST_P(TestLogToRedfishDiscrete, commitExpectNoThrow) |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 168 | { |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame] | 169 | EXPECT_NO_THROW(sut->commit("Test", Milliseconds{100'000}, 90.0)); |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 170 | } |
| 171 | |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 172 | class TestLogToRedfishDiscreteThrow : public TestLogToRedfishDiscrete |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 173 | {}; |
| 174 | |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 175 | INSTANTIATE_TEST_SUITE_P(_, TestLogToRedfishDiscreteThrow, |
| 176 | getIncorrectParams()); |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 177 | |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 178 | TEST_P(TestLogToRedfishDiscreteThrow, commitExpectToThrow) |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 179 | { |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame] | 180 | EXPECT_THROW(sut->commit("Test", Milliseconds{100'000}, 90.0), |
| 181 | std::runtime_error); |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 182 | } |
| 183 | |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 184 | namespace onChange |
| 185 | { |
| 186 | class TestLogToJournalDiscreteOnChange : public Test |
| 187 | { |
| 188 | public: |
| 189 | void SetUp() override |
| 190 | { |
| 191 | sut = std::make_unique<LogToJournal>(); |
| 192 | } |
| 193 | |
| 194 | std::unique_ptr<LogToJournal> sut; |
| 195 | }; |
| 196 | |
| 197 | TEST_F(TestLogToJournalDiscreteOnChange, commitExpectNoThrow) |
| 198 | { |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame] | 199 | EXPECT_NO_THROW(sut->commit("Test", Milliseconds{100'000}, 90.0)); |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | class TestLogToRedfishDiscreteOnChange : public Test |
| 203 | { |
| 204 | public: |
| 205 | void SetUp() override |
| 206 | { |
| 207 | sut = std::make_unique<LogToRedfish>(); |
| 208 | } |
| 209 | |
| 210 | std::unique_ptr<LogToRedfish> sut; |
| 211 | }; |
| 212 | |
| 213 | TEST_F(TestLogToRedfishDiscreteOnChange, commitExpectNoThrow) |
| 214 | { |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame] | 215 | EXPECT_NO_THROW(sut->commit("Test", Milliseconds{100'000}, 90.0)); |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 216 | } |
| 217 | } // namespace onChange |
| 218 | } // namespace discrete |
| 219 | |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 220 | class TestUpdateReport : public Test |
| 221 | { |
| 222 | public: |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 223 | TestUpdateReport() : messanger(DbusEnvironment::getIoc()) |
| 224 | {} |
| 225 | |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 226 | void make(std::vector<std::string> names) |
| 227 | { |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 228 | messanger.on_receive<messages::UpdateReportInd>( |
| 229 | [this](const auto& msg) { updateReport.Call(msg); }); |
| 230 | |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 231 | sut = std::make_unique<UpdateReport>( |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 232 | DbusEnvironment::getIoc(), |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 233 | std::make_shared<std::vector<std::string>>(std::move(names))); |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 234 | } |
| 235 | |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 236 | utils::Messanger messanger; |
| 237 | NiceMock<MockFunction<void(const messages::UpdateReportInd&)>> updateReport; |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 238 | std::unique_ptr<UpdateReport> sut; |
| 239 | }; |
| 240 | |
| 241 | TEST_F(TestUpdateReport, commitWhenReportNameIsEmptyExpectNoReportUpdate) |
| 242 | { |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 243 | EXPECT_CALL(updateReport, Call(_)).Times(0); |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 244 | |
| 245 | make({}); |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame] | 246 | sut->commit("Test", Milliseconds{100'000}, 90.0); |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | TEST_F(TestUpdateReport, commitExpectReportUpdate) |
| 250 | { |
| 251 | std::vector<std::string> names = {"Report1", "Report2", "Report3"}; |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 252 | EXPECT_CALL(updateReport, |
| 253 | Call(FieldsAre(UnorderedElementsAreArray(names)))); |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 254 | |
| 255 | make(names); |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame] | 256 | sut->commit("Test", Milliseconds{100'000}, 90.0); |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | } // namespace action |