blob: 2fa220ae73e7f8e20e852a3f1814cf000a275250 [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{
10
11using LogParam = std::pair<numeric::Type, double>;
12
13class TestLogToJournal : public Test, public WithParamInterface<LogParam>
14{
15 public:
16 void SetUp() override
17 {
18 auto [type, threshold] = GetParam();
19 sut = std::make_unique<LogToJournal>(type, threshold);
20 }
21
22 std::unique_ptr<LogToJournal> sut;
23};
24
25INSTANTIATE_TEST_SUITE_P(
26 LogToJournalParams, TestLogToJournal,
27 Values(std::make_pair(numeric::Type::upperCritical, 91.1),
28 std::make_pair(numeric::Type::lowerCritical, 91.2),
29 std::make_pair(numeric::Type::upperWarning, 88.5),
30 std::make_pair(numeric::Type::lowerWarning, 88.6)));
31
32TEST_P(TestLogToJournal, commitAnActionDoesNotThrow)
33{
34 EXPECT_NO_THROW(sut->commit("Test", 100'000, 90.0));
35}
36
37class TestLogToJournalThrow : public TestLogToJournal
38{};
39
40INSTANTIATE_TEST_SUITE_P(
41 _, TestLogToJournalThrow,
42 Values(std::make_pair(numeric::Type::upperCritical, 90.0),
43 std::make_pair(static_cast<numeric::Type>(-1), 88.0),
44 std::make_pair(static_cast<numeric::Type>(123), 123.0)));
45
46TEST_P(TestLogToJournalThrow, commitAnActionExpectThrow)
47{
48 EXPECT_THROW(sut->commit("Test", 100'000, 90.0), std::runtime_error);
49}
50
51class TestLogToRedfish : public Test, public WithParamInterface<LogParam>
52{
53 public:
54 void SetUp() override
55 {
56 auto [type, threshold] = GetParam();
57 sut = std::make_unique<LogToRedfish>(type, threshold);
58 }
59
60 std::unique_ptr<LogToRedfish> sut;
61};
62
63INSTANTIATE_TEST_SUITE_P(
64 LogToRedfishParams, TestLogToRedfish,
65 Values(std::make_pair(numeric::Type::upperCritical, 91.1),
66 std::make_pair(numeric::Type::lowerCritical, 91.4),
67 std::make_pair(numeric::Type::upperWarning, 88.6),
68 std::make_pair(numeric::Type::lowerWarning, 88.5)));
69
70TEST_P(TestLogToRedfish, commitExpectNoThrow)
71{
72 EXPECT_NO_THROW(sut->commit("Test", 100'000, 90.0));
73}
74
75class TestLogToRedfishThrow : public TestLogToRedfish
76{};
77
78INSTANTIATE_TEST_SUITE_P(
79 _, TestLogToRedfishThrow,
80 Values(std::make_pair(numeric::Type::upperCritical, 90.0),
81 std::make_pair(static_cast<numeric::Type>(-1), 88.5),
82 std::make_pair(static_cast<numeric::Type>(123), 123.6)));
83
84TEST_P(TestLogToRedfishThrow, commitExpectToThrow)
85{
86 EXPECT_THROW(sut->commit("Test", 100'000, 90.0), std::runtime_error);
87}
88
89class TestUpdateReport : public Test
90{
91 public:
92 void make(std::vector<std::string> names)
93 {
94 sut = std::make_unique<UpdateReport>(reportManager, std::move(names));
95 }
96
97 NiceMock<ReportManagerMock> reportManager;
98 std::unique_ptr<UpdateReport> sut;
99};
100
101TEST_F(TestUpdateReport, commitWhenReportNameIsEmptyExpectNoReportUpdate)
102{
103 EXPECT_CALL(reportManager, updateReport(_)).Times(0);
104
105 make({});
106 sut->commit("Test", 100'000, 90.0);
107}
108
109TEST_F(TestUpdateReport, commitExpectReportUpdate)
110{
111 std::vector<std::string> names = {"Report1", "Report2", "Report3"};
112 for (const auto& name : names)
113 {
114 EXPECT_CALL(reportManager, updateReport(name));
115 }
116
117 make(names);
118 sut->commit("Test", 100'000, 90.0);
119}
120
121} // namespace action