blob: 05a00ed441ebc53d462298fa80ba76968afce5f9 [file] [log] [blame]
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +02001#include "dbus_environment.hpp"
Krzysztof Grobelnyd2238192020-12-02 09:27:28 +00002#include "helpers.hpp"
Wludzik, Jozefe2362792020-10-27 17:23:55 +01003#include "mocks/json_storage_mock.hpp"
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +02004#include "mocks/report_factory_mock.hpp"
Wludzik, Jozefe2362792020-10-27 17:23:55 +01005#include "params/report_params.hpp"
6#include "report.hpp"
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +02007#include "report_manager.hpp"
Krzysztof Grobelnye8fc5752021-02-05 14:30:45 +00008#include "utils/conversion.hpp"
Wludzik, Jozefe2362792020-10-27 17:23:55 +01009#include "utils/transform.hpp"
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020010
11using namespace testing;
Krzysztof Grobelnye8fc5752021-02-05 14:30:45 +000012using namespace std::string_literals;
Wludzik, Jozefe2362792020-10-27 17:23:55 +010013using namespace std::chrono_literals;
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020014
15class TestReportManager : public Test
16{
17 public:
Wludzik, Jozefe2362792020-10-27 17:23:55 +010018 ReportParams reportParams;
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020019
20 std::unique_ptr<ReportFactoryMock> reportFactoryMockPtr =
21 std::make_unique<StrictMock<ReportFactoryMock>>();
22 ReportFactoryMock& reportFactoryMock = *reportFactoryMockPtr;
Wludzik, Jozefe2362792020-10-27 17:23:55 +010023
24 std::unique_ptr<StorageMock> storageMockPtr =
25 std::make_unique<NiceMock<StorageMock>>();
26 StorageMock& storageMock = *storageMockPtr;
27
Krzysztof Grobelnyd2238192020-12-02 09:27:28 +000028 std::unique_ptr<ReportMock> reportMockPtr =
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010029 std::make_unique<NiceMock<ReportMock>>(reportParams.reportId());
Krzysztof Grobelnyd2238192020-12-02 09:27:28 +000030 ReportMock& reportMock = *reportMockPtr;
31
Wludzik, Jozefe2362792020-10-27 17:23:55 +010032 std::unique_ptr<ReportManager> sut;
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020033
34 MockFunction<void(std::string)> checkPoint;
35
Wludzik, Jozefe2362792020-10-27 17:23:55 +010036 void SetUp() override
37 {
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000038 EXPECT_CALL(reportFactoryMock, convertMetricParams(_, _))
39 .Times(AnyNumber());
40
Wludzik, Jozefe2362792020-10-27 17:23:55 +010041 sut = std::make_unique<ReportManager>(std::move(reportFactoryMockPtr),
42 std::move(storageMockPtr),
43 DbusEnvironment::getObjServer());
44 }
45
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020046 void TearDown() override
47 {
48 DbusEnvironment::synchronizeIoc();
49 }
50
Krzysztof Grobelny51497a02021-11-09 14:56:22 +010051 template <class... Args>
52 requires(sizeof...(Args) > 1)
53 std::pair<boost::system::error_code, std::string> addReport(
54 Args&&... args)
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020055 {
56 std::promise<std::pair<boost::system::error_code, std::string>>
57 addReportPromise;
58 DbusEnvironment::getBus()->async_method_call(
59 [&addReportPromise](boost::system::error_code ec,
60 const std::string& path) {
61 addReportPromise.set_value({ec, path});
62 },
63 DbusEnvironment::serviceName(), ReportManager::reportManagerPath,
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000064 ReportManager::reportManagerIfaceName, "AddReportFutureVersion",
Krzysztof Grobelny51497a02021-11-09 14:56:22 +010065 std::forward<Args>(args)...);
Krzysztof Grobelnyf32f6fe2020-10-30 13:51:58 +010066 return DbusEnvironment::waitForFuture(addReportPromise.get_future());
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020067 }
68
Krzysztof Grobelny51497a02021-11-09 14:56:22 +010069 auto addReport(const ReportParams& params)
70 {
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010071 return addReport(params.reportId(), params.reportName(),
72 utils::enumToString(params.reportingType()),
73 utils::enumToString(params.reportUpdates()),
74 params.appendLimit(),
75 utils::transform(params.reportActions(),
76 [](const auto v) {
77 return utils::enumToString(v);
78 }),
79 params.interval().count(),
80 toReadingParameters(params.metricParameters()));
Krzysztof Grobelny51497a02021-11-09 14:56:22 +010081 }
82
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020083 template <class T>
Szymon Dompkee28aa532021-10-27 12:33:12 +020084 static T getProperty(const std::string& property)
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020085 {
Szymon Dompkee28aa532021-10-27 12:33:12 +020086 return DbusEnvironment::getProperty<T>(
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020087 ReportManager::reportManagerPath,
Szymon Dompkee28aa532021-10-27 12:33:12 +020088 ReportManager::reportManagerIfaceName, property);
Karol Niczyj32859b62021-05-19 10:20:46 +020089 }
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020090};
91
92TEST_F(TestReportManager, minInterval)
93{
94 EXPECT_THAT(getProperty<uint64_t>("MinInterval"),
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000095 Eq(ReportManager::minInterval.count()));
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +020096}
97
98TEST_F(TestReportManager, maxReports)
99{
Wludzik, Jozef503c1582020-12-11 14:48:01 +0100100 EXPECT_THAT(getProperty<size_t>("MaxReports"),
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +0200101 Eq(ReportManager::maxReports));
102}
103
104TEST_F(TestReportManager, addReport)
105{
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +0000106 EXPECT_CALL(reportFactoryMock, convertMetricParams(_, _));
107 reportFactoryMock.expectMake(reportParams, Ref(*sut), Ref(storageMock))
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +0200108 .WillOnce(Return(ByMove(std::move(reportMockPtr))));
109
Wludzik, Jozefe2362792020-10-27 17:23:55 +0100110 auto [ec, path] = addReport(reportParams);
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +0200111 EXPECT_THAT(ec.value(), Eq(boost::system::errc::success));
112 EXPECT_THAT(path, Eq(reportMock.getPath()));
113}
114
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +0100115TEST_F(TestReportManager, nameIsUsedToGenerateIdWhenIdIsEmptyInAddReport)
Karol Niczyj32859b62021-05-19 10:20:46 +0200116{
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +0100117 reportParams.reportId("ReportName");
118 reportParams.reportName("ReportName");
119
120 reportFactoryMock.expectMake(reportParams, Ref(*sut), Ref(storageMock));
121
122 auto [ec, path] = addReport(reportParams.reportId(""));
123
124 EXPECT_THAT(ec.value(), Eq(boost::system::errc::success));
125 EXPECT_THAT(path, Eq("/ReportName"));
126}
127
128TEST_F(TestReportManager, nameIsUsedToGenerateIdWhenIdIsNamespace)
129{
130 reportParams.reportId("Prefix/ReportName");
131 reportParams.reportName("ReportName");
132
133 reportFactoryMock.expectMake(reportParams, Ref(*sut), Ref(storageMock));
134
135 auto [ec, path] = addReport(reportParams.reportId("Prefix/"));
136
137 EXPECT_THAT(ec.value(), Eq(boost::system::errc::success));
138 EXPECT_THAT(path, Eq("/Prefix/ReportName"));
139}
140
141TEST_F(TestReportManager, addReportWithMaxLengthId)
142{
143 std::string reportId(ReportManager::maxReportIdLength, 'z');
144 reportParams.reportId(reportId);
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +0000145 reportFactoryMock.expectMake(reportParams, Ref(*sut), Ref(storageMock));
Karol Niczyj32859b62021-05-19 10:20:46 +0200146
147 auto [ec, path] = addReport(reportParams);
148
149 EXPECT_THAT(ec.value(), Eq(boost::system::errc::success));
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +0100150 EXPECT_THAT(path, Eq("/"s + reportId));
Karol Niczyj32859b62021-05-19 10:20:46 +0200151}
152
153TEST_F(TestReportManager, DISABLED_failToAddReportWithTooLongName)
154{
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +0000155 reportFactoryMock.expectMake(std::nullopt, Ref(*sut), Ref(storageMock))
Karol Niczyj32859b62021-05-19 10:20:46 +0200156 .Times(0);
157
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +0100158 reportParams.reportId(
159 std::string(ReportManager::maxReportIdLength + 1, 'z'));
Karol Niczyj32859b62021-05-19 10:20:46 +0200160
161 auto [ec, path] = addReport(reportParams);
162
163 EXPECT_THAT(ec.value(), Eq(boost::system::errc::invalid_argument));
164 EXPECT_THAT(path, Eq(std::string()));
165}
166
Wludzik, Jozefe2362792020-10-27 17:23:55 +0100167TEST_F(TestReportManager, DISABLED_failToAddReportTwice)
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +0200168{
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +0000169 reportFactoryMock.expectMake(reportParams, Ref(*sut), Ref(storageMock))
Krzysztof Grobelnyd2238192020-12-02 09:27:28 +0000170 .WillOnce(Return(ByMove(std::move(reportMockPtr))));
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +0200171
Wludzik, Jozefe2362792020-10-27 17:23:55 +0100172 addReport(reportParams);
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +0200173
Wludzik, Jozefe2362792020-10-27 17:23:55 +0100174 auto [ec, path] = addReport(reportParams);
Karol Niczyj32859b62021-05-19 10:20:46 +0200175
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +0200176 EXPECT_THAT(ec.value(), Eq(boost::system::errc::file_exists));
177 EXPECT_THAT(path, Eq(std::string()));
178}
179
Wludzik, Jozefe2362792020-10-27 17:23:55 +0100180TEST_F(TestReportManager, DISABLED_failToAddReportWithInvalidInterval)
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +0200181{
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +0000182 reportFactoryMock.expectMake(std::nullopt, Ref(*sut), Ref(storageMock))
Krzysztof Grobelnyd2238192020-12-02 09:27:28 +0000183 .Times(0);
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +0200184
Krzysztof Grobelny51497a02021-11-09 14:56:22 +0100185 reportParams.reportingType(ReportingType::periodic);
Wludzik, Jozefe2362792020-10-27 17:23:55 +0100186 reportParams.interval(reportParams.interval() - 1ms);
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +0200187
Wludzik, Jozefe2362792020-10-27 17:23:55 +0100188 auto [ec, path] = addReport(reportParams);
Karol Niczyj32859b62021-05-19 10:20:46 +0200189
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +0200190 EXPECT_THAT(ec.value(), Eq(boost::system::errc::invalid_argument));
191 EXPECT_THAT(path, Eq(std::string()));
192}
193
Wludzik, Jozefbc766b42020-12-08 16:06:22 +0100194TEST_F(TestReportManager, DISABLED_failToAddReportWithInvalidReportingType)
195{
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +0000196 reportFactoryMock.expectMake(std::nullopt, Ref(*sut), Ref(storageMock))
Wludzik, Jozefbc766b42020-12-08 16:06:22 +0100197 .Times(0);
198
Krzysztof Grobelny51497a02021-11-09 14:56:22 +0100199 auto [ec, path] = addReport(
200 reportParams.reportName(), "InvalidReportingType",
201 utils::transform(reportParams.reportActions(),
202 [](const auto v) { return utils::enumToString(v); }),
203 reportParams.interval().count(),
204 toReadingParameters(reportParams.metricParameters()));
Karol Niczyj32859b62021-05-19 10:20:46 +0200205
Wludzik, Jozefbc766b42020-12-08 16:06:22 +0100206 EXPECT_THAT(ec.value(), Eq(boost::system::errc::invalid_argument));
207 EXPECT_THAT(path, Eq(std::string()));
208}
209
210TEST_F(TestReportManager, DISABLED_failToAddReportWithMoreSensorsThanExpected)
211{
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +0000212 reportFactoryMock.expectMake(std::nullopt, Ref(*sut), Ref(storageMock))
Wludzik, Jozefbc766b42020-12-08 16:06:22 +0100213 .Times(0);
214
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +0000215 auto metricParams = reportParams.metricParameters();
Wludzik, Jozefbc766b42020-12-08 16:06:22 +0100216 for (size_t i = 0; i < ReportManager::maxReadingParams + 1; i++)
217 {
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +0000218 metricParams.push_back(metricParams.front());
Wludzik, Jozefbc766b42020-12-08 16:06:22 +0100219 }
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +0000220 reportParams.metricParameters(std::move(metricParams));
Wludzik, Jozefbc766b42020-12-08 16:06:22 +0100221
222 auto [ec, path] = addReport(reportParams);
Karol Niczyj32859b62021-05-19 10:20:46 +0200223
Wludzik, Jozefbc766b42020-12-08 16:06:22 +0100224 EXPECT_THAT(ec.value(), Eq(boost::system::errc::argument_list_too_long));
225 EXPECT_THAT(path, Eq(std::string()));
226}
227
Wludzik, Jozefe2362792020-10-27 17:23:55 +0100228TEST_F(TestReportManager, DISABLED_failToAddReportWhenMaxReportIsReached)
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +0200229{
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +0000230 reportFactoryMock.expectMake(std::nullopt, Ref(*sut), Ref(storageMock))
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +0200231 .Times(ReportManager::maxReports);
232
233 for (size_t i = 0; i < ReportManager::maxReports; i++)
234 {
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +0100235 reportParams.reportId(reportParams.reportName() + std::to_string(i));
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +0200236
Wludzik, Jozefe2362792020-10-27 17:23:55 +0100237 auto [ec, path] = addReport(reportParams);
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +0200238 EXPECT_THAT(ec.value(), Eq(boost::system::errc::success));
239 }
240
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +0100241 reportParams.reportId(reportParams.reportName() +
242 std::to_string(ReportManager::maxReports));
Wludzik, Jozefe2362792020-10-27 17:23:55 +0100243 auto [ec, path] = addReport(reportParams);
Karol Niczyj32859b62021-05-19 10:20:46 +0200244
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +0200245 EXPECT_THAT(ec.value(), Eq(boost::system::errc::too_many_files_open));
246 EXPECT_THAT(path, Eq(std::string()));
247}
248
249TEST_F(TestReportManager, removeReport)
250{
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +0200251 {
252 InSequence seq;
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +0000253 EXPECT_CALL(reportFactoryMock, convertMetricParams(_, _));
254 reportFactoryMock.expectMake(reportParams, Ref(*sut), Ref(storageMock))
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +0200255 .WillOnce(Return(ByMove(std::move(reportMockPtr))));
256 EXPECT_CALL(reportMock, Die());
257 EXPECT_CALL(checkPoint, Call("end"));
258 }
259
Wludzik, Jozefe2362792020-10-27 17:23:55 +0100260 addReport(reportParams);
261 sut->removeReport(&reportMock);
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +0200262 checkPoint.Call("end");
263}
264
265TEST_F(TestReportManager, removingReportThatIsNotInContainerHasNoEffect)
266{
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +0200267 {
268 InSequence seq;
269 EXPECT_CALL(checkPoint, Call("end"));
270 EXPECT_CALL(reportMock, Die());
271 }
272
Wludzik, Jozefe2362792020-10-27 17:23:55 +0100273 sut->removeReport(&reportMock);
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +0200274 checkPoint.Call("end");
275}
276
277TEST_F(TestReportManager, removingSameReportTwiceHasNoSideEffect)
278{
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +0200279 {
280 InSequence seq;
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +0000281 EXPECT_CALL(reportFactoryMock, convertMetricParams(_, _));
282 reportFactoryMock.expectMake(reportParams, Ref(*sut), Ref(storageMock))
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +0200283 .WillOnce(Return(ByMove(std::move(reportMockPtr))));
284 EXPECT_CALL(reportMock, Die());
285 EXPECT_CALL(checkPoint, Call("end"));
286 }
287
Wludzik, Jozefe2362792020-10-27 17:23:55 +0100288 addReport(reportParams);
289 sut->removeReport(&reportMock);
290 sut->removeReport(&reportMock);
Wludzik, Jozef2f9f9b82020-10-13 09:07:45 +0200291 checkPoint.Call("end");
292}
Wludzik, Jozefe2362792020-10-27 17:23:55 +0100293
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100294TEST_F(TestReportManager, updateReportCallsUpdateReadingsForExistReport)
295{
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +0000296 reportFactoryMock.expectMake(reportParams, Ref(*sut), Ref(storageMock))
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100297 .WillOnce(Return(ByMove(std::move(reportMockPtr))));
298 EXPECT_CALL(reportMock, updateReadings());
299
300 addReport(reportParams);
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +0100301 sut->updateReport(reportParams.reportId());
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100302}
303
304TEST_F(TestReportManager, updateReportDoNothingIfReportDoesNotExist)
305{
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +0000306 reportFactoryMock.expectMake(reportParams, Ref(*sut), Ref(storageMock))
Wludzik, Jozefd960e1f2021-01-08 09:25:59 +0100307 .WillOnce(Return(ByMove(std::move(reportMockPtr))));
308 EXPECT_CALL(reportMock, updateReadings()).Times(0);
309
310 addReport(reportParams);
311 sut->updateReport("NotAReport");
312}
313
Krzysztof Grobelnye8fc5752021-02-05 14:30:45 +0000314class TestReportManagerWithAggregationOperationType :
315 public TestReportManager,
316 public WithParamInterface<OperationType>
317{
318 public:
319 OperationType operationType = GetParam();
320};
321
322INSTANTIATE_TEST_SUITE_P(_, TestReportManagerWithAggregationOperationType,
323 Values(OperationType::single, OperationType::max,
324 OperationType::min, OperationType::avg,
325 OperationType::sum));
326
327TEST_P(TestReportManagerWithAggregationOperationType,
328 addReportWithDifferentOperationTypes)
329{
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +0000330 reportParams.metricParameters(
331 std::vector<LabeledMetricParameters>{{LabeledMetricParameters{
332 {LabeledSensorParameters{"Service",
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +0100333 "/xyz/openbmc_project/sensors/power/p1",
334 "Metadata1"}},
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +0000335 operationType,
336 "MetricId1",
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +0000337 CollectionTimeScope::point,
338 CollectionDuration(Milliseconds(0u))}}});
Krzysztof Grobelnye8fc5752021-02-05 14:30:45 +0000339
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +0000340 reportFactoryMock.expectMake(reportParams, Ref(*sut), Ref(storageMock))
Krzysztof Grobelnye8fc5752021-02-05 14:30:45 +0000341 .WillOnce(Return(ByMove(std::move(reportMockPtr))));
342
343 auto [ec, path] = addReport(reportParams);
Karol Niczyj32859b62021-05-19 10:20:46 +0200344
Krzysztof Grobelnye8fc5752021-02-05 14:30:45 +0000345 EXPECT_THAT(ec.value(), Eq(boost::system::errc::success));
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +0100346 EXPECT_THAT(path, Eq("/"s + reportParams.reportId()));
Krzysztof Grobelnye8fc5752021-02-05 14:30:45 +0000347}
348
Wludzik, Jozefe2362792020-10-27 17:23:55 +0100349class TestReportManagerStorage : public TestReportManager
350{
351 public:
352 using FilePath = interfaces::JsonStorage::FilePath;
353 using DirectoryPath = interfaces::JsonStorage::DirectoryPath;
354
355 void SetUp() override
356 {
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +0000357 EXPECT_CALL(reportFactoryMock, convertMetricParams(_, _)).Times(0);
358
Wludzik, Jozefe2362792020-10-27 17:23:55 +0100359 ON_CALL(storageMock, list())
360 .WillByDefault(Return(std::vector<FilePath>{FilePath("report1")}));
361 ON_CALL(storageMock, load(FilePath("report1")))
Krzysztof Grobelny6ccfcbf2020-11-04 09:31:36 +0100362 .WillByDefault(InvokeWithoutArgs([this] { return data; }));
Wludzik, Jozefe2362792020-10-27 17:23:55 +0100363 }
364
365 void makeReportManager()
366 {
367 sut = std::make_unique<ReportManager>(std::move(reportFactoryMockPtr),
368 std::move(storageMockPtr),
369 DbusEnvironment::getObjServer());
370 }
371
372 nlohmann::json data = nlohmann::json{
Lukasz Kazmierczak7e098e92021-09-16 15:59:56 +0200373 {"Enabled", reportParams.enabled()},
Wludzik, Jozefe2362792020-10-27 17:23:55 +0100374 {"Version", Report::reportVersion},
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +0100375 {"Id", reportParams.reportId()},
Wludzik, Jozefe2362792020-10-27 17:23:55 +0100376 {"Name", reportParams.reportName()},
Krzysztof Grobelny51497a02021-11-09 14:56:22 +0100377 {"ReportingType", utils::toUnderlying(reportParams.reportingType())},
378 {"ReportActions", reportParams.reportActions()},
Wludzik, Jozefe2362792020-10-27 17:23:55 +0100379 {"Interval", reportParams.interval().count()},
Krzysztof Grobelny51497a02021-11-09 14:56:22 +0100380 {"ReportUpdates", utils::toUnderlying(reportParams.reportUpdates())},
Szymon Dompke3eb56862021-09-20 15:32:04 +0200381 {"AppendLimit", reportParams.appendLimit()},
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +0000382 {"ReadingParameters", reportParams.metricParameters()}};
Wludzik, Jozefe2362792020-10-27 17:23:55 +0100383};
384
385TEST_F(TestReportManagerStorage, reportManagerCtorAddReportFromStorage)
386{
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +0000387 reportFactoryMock.expectMake(reportParams, _, Ref(storageMock));
Wludzik, Jozefe2362792020-10-27 17:23:55 +0100388
389 makeReportManager();
390}
391
392TEST_F(TestReportManagerStorage,
393 reportManagerCtorRemoveFileIfVersionDoesNotMatch)
394{
395 data["Version"] = Report::reportVersion - 1;
396
Wludzik, Jozefe2362792020-10-27 17:23:55 +0100397 EXPECT_CALL(storageMock, remove(FilePath("report1")));
398
399 makeReportManager();
400}
401
402TEST_F(TestReportManagerStorage,
403 reportManagerCtorRemoveFileIfIntervalHasWrongType)
404{
405 data["Interval"] = "1000";
406
Wludzik, Jozefe2362792020-10-27 17:23:55 +0100407 EXPECT_CALL(storageMock, remove(FilePath("report1")));
408
409 makeReportManager();
410}