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 | { |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame] | 63 | EXPECT_THROW(sut->commit("Test", Milliseconds{100'000}, commmitValue), |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 64 | std::runtime_error); |
| 65 | } |
| 66 | |
| 67 | class 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 | |
| 81 | INSTANTIATE_TEST_SUITE_P(LogToRedfishNumericParams, TestLogToRedfishNumeric, |
| 82 | getCorrectParams()); |
| 83 | |
| 84 | TEST_P(TestLogToRedfishNumeric, commitExpectNoThrow) |
| 85 | { |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame] | 86 | EXPECT_NO_THROW(sut->commit("Test", Milliseconds{100'000}, commmitValue)); |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | class TestLogToRedfishNumericThrow : public TestLogToRedfishNumeric |
| 90 | {}; |
| 91 | |
| 92 | INSTANTIATE_TEST_SUITE_P(_, TestLogToRedfishNumericThrow, getIncorrectParams()); |
| 93 | |
| 94 | TEST_P(TestLogToRedfishNumericThrow, commitExpectToThrow) |
| 95 | { |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame] | 96 | EXPECT_THROW(sut->commit("Test", Milliseconds{100'000}, commmitValue), |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 97 | std::runtime_error); |
| 98 | } |
| 99 | |
| 100 | } // namespace numeric |
| 101 | |
| 102 | namespace discrete |
| 103 | { |
| 104 | using LogParam = ::discrete::Severity; |
| 105 | |
| 106 | static auto getCorrectParams() |
| 107 | { |
| 108 | return Values(::discrete::Severity::critical, ::discrete::Severity::warning, |
| 109 | ::discrete::Severity::ok); |
| 110 | } |
| 111 | |
| 112 | static auto getIncorrectParams() |
| 113 | { |
| 114 | return Values(static_cast<::discrete::Severity>(-1), |
| 115 | static_cast<::discrete::Severity>(42)); |
| 116 | } |
| 117 | |
| 118 | class 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, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | std::unique_ptr<LogToJournal> sut; |
| 130 | }; |
| 131 | |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 132 | INSTANTIATE_TEST_SUITE_P(LogToJournalDiscreteParams, TestLogToJournalDiscrete, |
| 133 | getCorrectParams()); |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 134 | |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 135 | TEST_P(TestLogToJournalDiscrete, commitAnActionDoesNotThrow) |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 136 | { |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame] | 137 | EXPECT_NO_THROW(sut->commit("Test", Milliseconds{100'000}, 90.0)); |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 138 | } |
| 139 | |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 140 | class TestLogToJournalDiscreteThrow : public TestLogToJournalDiscrete |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 141 | {}; |
| 142 | |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 143 | INSTANTIATE_TEST_SUITE_P(_, TestLogToJournalDiscreteThrow, |
| 144 | getIncorrectParams()); |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 145 | |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 146 | TEST_P(TestLogToJournalDiscreteThrow, commitAnActionExpectThrow) |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 147 | { |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame] | 148 | EXPECT_THROW(sut->commit("Test", Milliseconds{100'000}, 90.0), |
| 149 | std::runtime_error); |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 150 | } |
| 151 | |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 152 | class TestLogToRedfishDiscrete : |
| 153 | public Test, |
| 154 | public WithParamInterface<LogParam> |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 155 | { |
| 156 | public: |
| 157 | void SetUp() override |
| 158 | { |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 159 | auto severity = GetParam(); |
| 160 | sut = std::make_unique<LogToRedfish>(severity); |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | std::unique_ptr<LogToRedfish> sut; |
| 164 | }; |
| 165 | |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 166 | INSTANTIATE_TEST_SUITE_P(LogToRedfishDiscreteParams, TestLogToRedfishDiscrete, |
| 167 | getCorrectParams()); |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 168 | |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 169 | TEST_P(TestLogToRedfishDiscrete, commitExpectNoThrow) |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 170 | { |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame] | 171 | EXPECT_NO_THROW(sut->commit("Test", Milliseconds{100'000}, 90.0)); |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 172 | } |
| 173 | |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 174 | class TestLogToRedfishDiscreteThrow : public TestLogToRedfishDiscrete |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 175 | {}; |
| 176 | |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 177 | INSTANTIATE_TEST_SUITE_P(_, TestLogToRedfishDiscreteThrow, |
| 178 | getIncorrectParams()); |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 179 | |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 180 | TEST_P(TestLogToRedfishDiscreteThrow, commitExpectToThrow) |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 181 | { |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame] | 182 | EXPECT_THROW(sut->commit("Test", Milliseconds{100'000}, 90.0), |
| 183 | std::runtime_error); |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 184 | } |
| 185 | |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 186 | namespace onChange |
| 187 | { |
| 188 | class 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 | |
| 199 | TEST_F(TestLogToJournalDiscreteOnChange, commitExpectNoThrow) |
| 200 | { |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame] | 201 | EXPECT_NO_THROW(sut->commit("Test", Milliseconds{100'000}, 90.0)); |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | class 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 | |
| 215 | TEST_F(TestLogToRedfishDiscreteOnChange, commitExpectNoThrow) |
| 216 | { |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame] | 217 | EXPECT_NO_THROW(sut->commit("Test", Milliseconds{100'000}, 90.0)); |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame] | 218 | } |
| 219 | } // namespace onChange |
| 220 | } // namespace discrete |
| 221 | |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 222 | class TestUpdateReport : public Test |
| 223 | { |
| 224 | public: |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 225 | TestUpdateReport() : messanger(DbusEnvironment::getIoc()) |
| 226 | {} |
| 227 | |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 228 | void make(std::vector<std::string> names) |
| 229 | { |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 230 | messanger.on_receive<messages::UpdateReportInd>( |
| 231 | [this](const auto& msg) { updateReport.Call(msg); }); |
| 232 | |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 233 | sut = std::make_unique<UpdateReport>( |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 234 | DbusEnvironment::getIoc(), |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 235 | std::make_shared<std::vector<std::string>>(std::move(names))); |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 236 | } |
| 237 | |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 238 | utils::Messanger messanger; |
| 239 | NiceMock<MockFunction<void(const messages::UpdateReportInd&)>> updateReport; |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 240 | std::unique_ptr<UpdateReport> sut; |
| 241 | }; |
| 242 | |
| 243 | TEST_F(TestUpdateReport, commitWhenReportNameIsEmptyExpectNoReportUpdate) |
| 244 | { |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 245 | EXPECT_CALL(updateReport, Call(_)).Times(0); |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 246 | |
| 247 | make({}); |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame] | 248 | sut->commit("Test", Milliseconds{100'000}, 90.0); |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | TEST_F(TestUpdateReport, commitExpectReportUpdate) |
| 252 | { |
| 253 | std::vector<std::string> names = {"Report1", "Report2", "Report3"}; |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 254 | EXPECT_CALL(updateReport, |
| 255 | Call(FieldsAre(UnorderedElementsAreArray(names)))); |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 256 | |
| 257 | make(names); |
Krzysztof Grobelny | 51f0fd5 | 2021-12-28 16:32:08 +0100 | [diff] [blame] | 258 | sut->commit("Test", Milliseconds{100'000}, 90.0); |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | } // namespace action |