Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 1 | #include "dbus_environment.hpp" |
Krzysztof Grobelny | d223819 | 2020-12-02 09:27:28 +0000 | [diff] [blame] | 2 | #include "helpers.hpp" |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 3 | #include "interfaces/trigger_manager.hpp" |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 4 | #include "mocks/json_storage_mock.hpp" |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 5 | #include "mocks/report_factory_mock.hpp" |
Szymon Dompke | b4ef22e | 2022-02-07 15:15:12 +0100 | [diff] [blame] | 6 | #include "mocks/trigger_manager_mock.hpp" |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 7 | #include "params/report_params.hpp" |
| 8 | #include "report.hpp" |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 9 | #include "report_manager.hpp" |
Krzysztof Grobelny | e8fc575 | 2021-02-05 14:30:45 +0000 | [diff] [blame] | 10 | #include "utils/conversion.hpp" |
Szymon Dompke | 32305f1 | 2022-07-05 15:37:21 +0200 | [diff] [blame] | 11 | #include "utils/dbus_path_utils.hpp" |
| 12 | #include "utils/string_utils.hpp" |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 13 | #include "utils/transform.hpp" |
Szymon Dompke | 32305f1 | 2022-07-05 15:37:21 +0200 | [diff] [blame] | 14 | #include "utils/tstring.hpp" |
Krzysztof Grobelny | a8182be | 2022-07-04 11:26:20 +0200 | [diff] [blame^] | 15 | #include "utils/variant_utils.hpp" |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 16 | |
| 17 | using namespace testing; |
Krzysztof Grobelny | e8fc575 | 2021-02-05 14:30:45 +0000 | [diff] [blame] | 18 | using namespace std::string_literals; |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 19 | using namespace std::chrono_literals; |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 20 | |
Krzysztof Grobelny | a8182be | 2022-07-04 11:26:20 +0200 | [diff] [blame^] | 21 | using AddReportFutureVersionVariantForSet = |
| 22 | utils::WithoutMonostate<AddReportFutureVersionVariant>; |
| 23 | |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 24 | class TestReportManager : public Test |
| 25 | { |
| 26 | public: |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 27 | ReportParams reportParams; |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 28 | |
| 29 | std::unique_ptr<ReportFactoryMock> reportFactoryMockPtr = |
| 30 | std::make_unique<StrictMock<ReportFactoryMock>>(); |
| 31 | ReportFactoryMock& reportFactoryMock = *reportFactoryMockPtr; |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 32 | |
| 33 | std::unique_ptr<StorageMock> storageMockPtr = |
| 34 | std::make_unique<NiceMock<StorageMock>>(); |
| 35 | StorageMock& storageMock = *storageMockPtr; |
| 36 | |
Krzysztof Grobelny | d223819 | 2020-12-02 09:27:28 +0000 | [diff] [blame] | 37 | std::unique_ptr<ReportMock> reportMockPtr = |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 38 | std::make_unique<NiceMock<ReportMock>>(reportParams.reportId()); |
Krzysztof Grobelny | d223819 | 2020-12-02 09:27:28 +0000 | [diff] [blame] | 39 | ReportMock& reportMock = *reportMockPtr; |
| 40 | |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 41 | std::unique_ptr<ReportManager> sut; |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 42 | |
| 43 | MockFunction<void(std::string)> checkPoint; |
| 44 | |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 45 | void SetUp() override |
| 46 | { |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 47 | EXPECT_CALL(reportFactoryMock, convertMetricParams(_, _)) |
| 48 | .Times(AnyNumber()); |
| 49 | |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 50 | sut = std::make_unique<ReportManager>(std::move(reportFactoryMockPtr), |
| 51 | std::move(storageMockPtr), |
| 52 | DbusEnvironment::getObjServer()); |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 53 | } |
| 54 | |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 55 | void TearDown() override |
| 56 | { |
| 57 | DbusEnvironment::synchronizeIoc(); |
| 58 | } |
| 59 | |
Krzysztof Grobelny | a8182be | 2022-07-04 11:26:20 +0200 | [diff] [blame^] | 60 | std::pair<boost::system::error_code, std::string> |
| 61 | addReport(const std::vector< |
| 62 | std::pair<std::string, AddReportFutureVersionVariantForSet>>& |
| 63 | properties) |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 64 | { |
| 65 | std::promise<std::pair<boost::system::error_code, std::string>> |
| 66 | addReportPromise; |
| 67 | DbusEnvironment::getBus()->async_method_call( |
| 68 | [&addReportPromise](boost::system::error_code ec, |
| 69 | const std::string& path) { |
| 70 | addReportPromise.set_value({ec, path}); |
| 71 | }, |
| 72 | DbusEnvironment::serviceName(), ReportManager::reportManagerPath, |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 73 | ReportManager::reportManagerIfaceName, "AddReportFutureVersion", |
Krzysztof Grobelny | a8182be | 2022-07-04 11:26:20 +0200 | [diff] [blame^] | 74 | properties); |
Krzysztof Grobelny | f32f6fe | 2020-10-30 13:51:58 +0100 | [diff] [blame] | 75 | return DbusEnvironment::waitForFuture(addReportPromise.get_future()); |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 76 | } |
| 77 | |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 78 | auto addReport(const ReportParams& params) |
| 79 | { |
Krzysztof Grobelny | a8182be | 2022-07-04 11:26:20 +0200 | [diff] [blame^] | 80 | std::vector<std::pair<std::string, AddReportFutureVersionVariantForSet>> |
| 81 | properties; |
| 82 | |
| 83 | properties.emplace_back("Id", params.reportId()); |
| 84 | properties.emplace_back("Name", params.reportName()); |
| 85 | properties.emplace_back("ReportingType", |
| 86 | utils::enumToString(params.reportingType())); |
| 87 | properties.emplace_back("ReportUpdates", |
| 88 | utils::enumToString(params.reportUpdates())); |
| 89 | properties.emplace_back("AppendLimit", params.appendLimit()); |
| 90 | properties.emplace_back("Enabled", params.enabled()); |
| 91 | properties.emplace_back( |
| 92 | "ReportActions", |
| 93 | utils::transform(params.reportActions(), [](const auto v) { |
| 94 | return utils::enumToString(v); |
| 95 | })); |
| 96 | properties.emplace_back("Interval", params.interval().count()); |
| 97 | properties.emplace_back("MetricParams", |
| 98 | toReadingParameters(params.metricParameters())); |
| 99 | |
| 100 | return addReport(properties); |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 101 | } |
| 102 | |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 103 | template <class T> |
Szymon Dompke | e28aa53 | 2021-10-27 12:33:12 +0200 | [diff] [blame] | 104 | static T getProperty(const std::string& property) |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 105 | { |
Szymon Dompke | e28aa53 | 2021-10-27 12:33:12 +0200 | [diff] [blame] | 106 | return DbusEnvironment::getProperty<T>( |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 107 | ReportManager::reportManagerPath, |
Szymon Dompke | e28aa53 | 2021-10-27 12:33:12 +0200 | [diff] [blame] | 108 | ReportManager::reportManagerIfaceName, property); |
Karol Niczyj | 32859b6 | 2021-05-19 10:20:46 +0200 | [diff] [blame] | 109 | } |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 110 | }; |
| 111 | |
| 112 | TEST_F(TestReportManager, minInterval) |
| 113 | { |
| 114 | EXPECT_THAT(getProperty<uint64_t>("MinInterval"), |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 115 | Eq(ReportManager::minInterval.count())); |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | TEST_F(TestReportManager, maxReports) |
| 119 | { |
Wludzik, Jozef | 503c158 | 2020-12-11 14:48:01 +0100 | [diff] [blame] | 120 | EXPECT_THAT(getProperty<size_t>("MaxReports"), |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 121 | Eq(ReportManager::maxReports)); |
| 122 | } |
| 123 | |
Krzysztof Grobelny | 60fee07 | 2022-01-13 16:25:04 +0100 | [diff] [blame] | 124 | TEST_F(TestReportManager, returnsPropertySupportedOperationTypes) |
| 125 | { |
| 126 | EXPECT_THAT( |
| 127 | getProperty<std::vector<std::string>>("SupportedOperationTypes"), |
| 128 | UnorderedElementsAre("Maximum", "Minimum", "Average", "Summation")); |
| 129 | } |
| 130 | |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 131 | TEST_F(TestReportManager, addReport) |
| 132 | { |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 133 | EXPECT_CALL(reportFactoryMock, convertMetricParams(_, _)); |
| 134 | reportFactoryMock.expectMake(reportParams, Ref(*sut), Ref(storageMock)) |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 135 | .WillOnce(Return(ByMove(std::move(reportMockPtr)))); |
| 136 | |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 137 | auto [ec, path] = addReport(reportParams); |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 138 | EXPECT_THAT(ec.value(), Eq(boost::system::errc::success)); |
| 139 | EXPECT_THAT(path, Eq(reportMock.getPath())); |
| 140 | } |
| 141 | |
Krzysztof Grobelny | a8182be | 2022-07-04 11:26:20 +0200 | [diff] [blame^] | 142 | TEST_F(TestReportManager, addDisabledReport) |
| 143 | { |
| 144 | reportParams.enabled(false); |
| 145 | |
| 146 | EXPECT_CALL(reportFactoryMock, convertMetricParams(_, _)); |
| 147 | reportFactoryMock.expectMake(reportParams, Ref(*sut), Ref(storageMock)) |
| 148 | .WillOnce(Return(ByMove(std::move(reportMockPtr)))); |
| 149 | |
| 150 | auto [ec, path] = addReport(reportParams); |
| 151 | EXPECT_THAT(ec.value(), Eq(boost::system::errc::success)); |
| 152 | EXPECT_THAT(path, Eq(reportMock.getPath())); |
| 153 | } |
| 154 | |
| 155 | TEST_F(TestReportManager, addReportWithOnlyDefaultParams) |
| 156 | { |
| 157 | EXPECT_CALL(reportFactoryMock, convertMetricParams(_, _)); |
| 158 | EXPECT_CALL(reportFactoryMock, |
| 159 | make("Report"s, "Report"s, ReportingType::onRequest, |
| 160 | std::vector<ReportAction>{}, Milliseconds{}, 0, |
| 161 | ReportUpdates::overwrite, _, _, |
| 162 | std::vector<LabeledMetricParameters>{}, true, Readings{})) |
| 163 | .WillOnce(Return(ByMove(std::move(reportMockPtr)))); |
| 164 | |
| 165 | auto [ec, path] = addReport( |
| 166 | std::vector< |
| 167 | std::pair<std::string, AddReportFutureVersionVariantForSet>>{}); |
| 168 | EXPECT_THAT(ec.value(), Eq(boost::system::errc::success)); |
| 169 | EXPECT_THAT(path, Eq(reportMock.getPath())); |
| 170 | } |
| 171 | |
Krzysztof Grobelny | f7ea299 | 2022-01-27 11:04:58 +0100 | [diff] [blame] | 172 | TEST_F(TestReportManager, addOnChangeReport) |
| 173 | { |
| 174 | EXPECT_CALL(reportFactoryMock, convertMetricParams(_, _)); |
| 175 | reportFactoryMock |
| 176 | .expectMake(reportParams.reportingType(ReportingType::onChange), |
| 177 | Ref(*sut), Ref(storageMock)) |
| 178 | .WillOnce(Return(ByMove(std::move(reportMockPtr)))); |
| 179 | |
| 180 | auto [ec, path] = addReport(reportParams); |
| 181 | EXPECT_THAT(ec.value(), Eq(boost::system::errc::success)); |
| 182 | EXPECT_THAT(path, Eq(reportMock.getPath())); |
| 183 | } |
| 184 | |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 185 | TEST_F(TestReportManager, nameIsUsedToGenerateIdWhenIdIsEmptyInAddReport) |
Karol Niczyj | 32859b6 | 2021-05-19 10:20:46 +0200 | [diff] [blame] | 186 | { |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 187 | reportParams.reportId("ReportName"); |
| 188 | reportParams.reportName("ReportName"); |
| 189 | |
| 190 | reportFactoryMock.expectMake(reportParams, Ref(*sut), Ref(storageMock)); |
| 191 | |
| 192 | auto [ec, path] = addReport(reportParams.reportId("")); |
| 193 | |
| 194 | EXPECT_THAT(ec.value(), Eq(boost::system::errc::success)); |
| 195 | EXPECT_THAT(path, Eq("/ReportName")); |
| 196 | } |
| 197 | |
| 198 | TEST_F(TestReportManager, nameIsUsedToGenerateIdWhenIdIsNamespace) |
| 199 | { |
| 200 | reportParams.reportId("Prefix/ReportName"); |
| 201 | reportParams.reportName("ReportName"); |
| 202 | |
| 203 | reportFactoryMock.expectMake(reportParams, Ref(*sut), Ref(storageMock)); |
| 204 | |
| 205 | auto [ec, path] = addReport(reportParams.reportId("Prefix/")); |
| 206 | |
| 207 | EXPECT_THAT(ec.value(), Eq(boost::system::errc::success)); |
| 208 | EXPECT_THAT(path, Eq("/Prefix/ReportName")); |
| 209 | } |
| 210 | |
| 211 | TEST_F(TestReportManager, addReportWithMaxLengthId) |
| 212 | { |
Szymon Dompke | 32305f1 | 2022-07-05 15:37:21 +0200 | [diff] [blame] | 213 | std::string reportId = utils::string_utils::getMaxId(); |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 214 | reportParams.reportId(reportId); |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 215 | reportFactoryMock.expectMake(reportParams, Ref(*sut), Ref(storageMock)); |
Karol Niczyj | 32859b6 | 2021-05-19 10:20:46 +0200 | [diff] [blame] | 216 | |
| 217 | auto [ec, path] = addReport(reportParams); |
| 218 | |
| 219 | EXPECT_THAT(ec.value(), Eq(boost::system::errc::success)); |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 220 | EXPECT_THAT(path, Eq("/"s + reportId)); |
Karol Niczyj | 32859b6 | 2021-05-19 10:20:46 +0200 | [diff] [blame] | 221 | } |
| 222 | |
Szymon Dompke | 32305f1 | 2022-07-05 15:37:21 +0200 | [diff] [blame] | 223 | TEST_F(TestReportManager, addReportWithMaxLengthPrefix) |
| 224 | { |
| 225 | std::string reportId = utils::string_utils::getMaxPrefix() + "/MyId"; |
| 226 | reportParams.reportId(reportId); |
| 227 | reportFactoryMock.expectMake(reportParams, Ref(*sut), Ref(storageMock)); |
| 228 | |
| 229 | auto [ec, path] = addReport(reportParams); |
| 230 | |
| 231 | EXPECT_THAT(ec.value(), Eq(boost::system::errc::success)); |
| 232 | EXPECT_THAT(path, Eq("/"s + reportId)); |
| 233 | } |
| 234 | |
| 235 | TEST_F(TestReportManager, addReportWithMaxLengthName) |
| 236 | { |
| 237 | reportParams.reportName(utils::string_utils::getMaxName()); |
| 238 | reportFactoryMock.expectMake(reportParams, Ref(*sut), Ref(storageMock)); |
| 239 | |
| 240 | auto [ec, path] = addReport(reportParams); |
| 241 | |
| 242 | EXPECT_THAT(ec.value(), Eq(boost::system::errc::success)); |
| 243 | EXPECT_THAT(path, Eq("/"s + reportParams.reportId())); |
| 244 | } |
| 245 | |
| 246 | TEST_F(TestReportManager, addReportWithMaxLengthMetricId) |
| 247 | { |
| 248 | namespace ts = utils::tstring; |
| 249 | std::vector<LabeledMetricParameters> newMetricParams{ |
| 250 | {LabeledMetricParameters{ |
| 251 | {LabeledSensorInfo{"Service", |
| 252 | "/xyz/openbmc_project/sensors/power/p1", |
| 253 | "metadata1"}}, |
| 254 | OperationType::avg, |
| 255 | utils::string_utils::getMaxId(), |
| 256 | CollectionTimeScope::point, |
| 257 | CollectionDuration(Milliseconds(0u))}}}; |
| 258 | |
| 259 | reportParams.metricParameters(newMetricParams); |
| 260 | reportFactoryMock.expectMake(reportParams, Ref(*sut), Ref(storageMock)); |
| 261 | |
| 262 | auto [ec, path] = addReport(reportParams); |
| 263 | |
| 264 | EXPECT_THAT(ec.value(), Eq(boost::system::errc::success)); |
| 265 | EXPECT_THAT(path, Eq("/"s + reportParams.reportId())); |
| 266 | } |
| 267 | |
| 268 | TEST_F(TestReportManager, DISABLED_failToAddReportWithTooLongFullId) |
Karol Niczyj | 32859b6 | 2021-05-19 10:20:46 +0200 | [diff] [blame] | 269 | { |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 270 | reportFactoryMock.expectMake(std::nullopt, Ref(*sut), Ref(storageMock)) |
Karol Niczyj | 32859b6 | 2021-05-19 10:20:46 +0200 | [diff] [blame] | 271 | .Times(0); |
| 272 | |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 273 | reportParams.reportId( |
Szymon Dompke | 32305f1 | 2022-07-05 15:37:21 +0200 | [diff] [blame] | 274 | std::string(utils::constants::maxReportFullIdLength + 1, 'z')); |
| 275 | |
| 276 | auto [ec, path] = addReport(reportParams); |
| 277 | |
| 278 | EXPECT_THAT(ec.value(), Eq(boost::system::errc::invalid_argument)); |
| 279 | EXPECT_THAT(path, Eq(std::string())); |
| 280 | } |
| 281 | |
| 282 | TEST_F(TestReportManager, DISABLED_failToAddReportWithTooLongId) |
| 283 | { |
| 284 | reportFactoryMock.expectMake(std::nullopt, Ref(*sut), Ref(storageMock)) |
| 285 | .Times(0); |
| 286 | |
| 287 | reportParams.reportId(utils::string_utils::getTooLongId()); |
| 288 | |
| 289 | auto [ec, path] = addReport(reportParams); |
| 290 | |
| 291 | EXPECT_THAT(ec.value(), Eq(boost::system::errc::invalid_argument)); |
| 292 | EXPECT_THAT(path, Eq(std::string())); |
| 293 | } |
| 294 | |
| 295 | TEST_F(TestReportManager, DISABLED_failToAddReportWithTooLongPrefix) |
| 296 | { |
| 297 | reportFactoryMock.expectMake(std::nullopt, Ref(*sut), Ref(storageMock)) |
| 298 | .Times(0); |
| 299 | |
| 300 | reportParams.reportId(utils::string_utils::getTooLongPrefix() + "/MyId"); |
| 301 | |
| 302 | auto [ec, path] = addReport(reportParams); |
| 303 | |
| 304 | EXPECT_THAT(ec.value(), Eq(boost::system::errc::invalid_argument)); |
| 305 | EXPECT_THAT(path, Eq(std::string())); |
| 306 | } |
| 307 | |
| 308 | TEST_F(TestReportManager, DISABLED_failToAddReportWithTooManyPrefixes) |
| 309 | { |
| 310 | reportFactoryMock.expectMake(std::nullopt, Ref(*sut), Ref(storageMock)) |
| 311 | .Times(0); |
| 312 | |
| 313 | std::string reportId; |
| 314 | for (size_t i = 0; i < utils::constants::maxPrefixesInId + 1; i++) |
| 315 | { |
| 316 | reportId += "prefix/"; |
| 317 | } |
| 318 | reportId += "MyId"; |
| 319 | |
| 320 | reportParams.reportId(reportId); |
| 321 | |
| 322 | auto [ec, path] = addReport(reportParams); |
| 323 | |
| 324 | EXPECT_THAT(ec.value(), Eq(boost::system::errc::invalid_argument)); |
| 325 | EXPECT_THAT(path, Eq(std::string())); |
| 326 | } |
| 327 | |
| 328 | TEST_F(TestReportManager, DISABLED_failToAddReportWithTooLongName) |
| 329 | { |
| 330 | reportFactoryMock.expectMake(std::nullopt, Ref(*sut), Ref(storageMock)) |
| 331 | .Times(0); |
| 332 | |
| 333 | reportParams.reportName(utils::string_utils::getTooLongName()); |
| 334 | |
| 335 | auto [ec, path] = addReport(reportParams); |
| 336 | |
| 337 | EXPECT_THAT(ec.value(), Eq(boost::system::errc::invalid_argument)); |
| 338 | EXPECT_THAT(path, Eq(std::string())); |
| 339 | } |
| 340 | |
| 341 | TEST_F(TestReportManager, DISABLED_failToAddReportWithTooLongMetricId) |
| 342 | { |
| 343 | namespace ts = utils::tstring; |
| 344 | |
| 345 | std::vector<LabeledMetricParameters> newMetricParams{ |
| 346 | {LabeledMetricParameters{ |
| 347 | {LabeledSensorInfo{"Service", |
| 348 | "/xyz/openbmc_project/sensors/power/p1", |
| 349 | "metadata1"}}, |
| 350 | OperationType::avg, |
| 351 | utils::string_utils::getTooLongId(), |
| 352 | CollectionTimeScope::point, |
| 353 | CollectionDuration(Milliseconds(0u))}}}; |
| 354 | |
| 355 | reportFactoryMock.expectMake(std::nullopt, Ref(*sut), Ref(storageMock)) |
| 356 | .Times(0); |
| 357 | |
| 358 | reportParams.metricParameters(newMetricParams); |
Karol Niczyj | 32859b6 | 2021-05-19 10:20:46 +0200 | [diff] [blame] | 359 | |
| 360 | auto [ec, path] = addReport(reportParams); |
| 361 | |
| 362 | EXPECT_THAT(ec.value(), Eq(boost::system::errc::invalid_argument)); |
| 363 | EXPECT_THAT(path, Eq(std::string())); |
| 364 | } |
| 365 | |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 366 | TEST_F(TestReportManager, DISABLED_failToAddReportTwice) |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 367 | { |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 368 | reportFactoryMock.expectMake(reportParams, Ref(*sut), Ref(storageMock)) |
Krzysztof Grobelny | d223819 | 2020-12-02 09:27:28 +0000 | [diff] [blame] | 369 | .WillOnce(Return(ByMove(std::move(reportMockPtr)))); |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 370 | |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 371 | addReport(reportParams); |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 372 | |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 373 | auto [ec, path] = addReport(reportParams); |
Karol Niczyj | 32859b6 | 2021-05-19 10:20:46 +0200 | [diff] [blame] | 374 | |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 375 | EXPECT_THAT(ec.value(), Eq(boost::system::errc::file_exists)); |
| 376 | EXPECT_THAT(path, Eq(std::string())); |
| 377 | } |
| 378 | |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 379 | TEST_F(TestReportManager, DISABLED_failToAddReportWithInvalidInterval) |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 380 | { |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 381 | reportFactoryMock.expectMake(std::nullopt, Ref(*sut), Ref(storageMock)) |
Krzysztof Grobelny | d223819 | 2020-12-02 09:27:28 +0000 | [diff] [blame] | 382 | .Times(0); |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 383 | |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 384 | reportParams.reportingType(ReportingType::periodic); |
Krzysztof Grobelny | 973b4bb | 2022-04-25 17:07:27 +0200 | [diff] [blame] | 385 | reportParams.interval(ReportManager::minInterval - 1ms); |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 386 | |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 387 | auto [ec, path] = addReport(reportParams); |
Karol Niczyj | 32859b6 | 2021-05-19 10:20:46 +0200 | [diff] [blame] | 388 | |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 389 | EXPECT_THAT(ec.value(), Eq(boost::system::errc::invalid_argument)); |
| 390 | EXPECT_THAT(path, Eq(std::string())); |
| 391 | } |
| 392 | |
Wludzik, Jozef | bc766b4 | 2020-12-08 16:06:22 +0100 | [diff] [blame] | 393 | TEST_F(TestReportManager, DISABLED_failToAddReportWithInvalidReportingType) |
| 394 | { |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 395 | reportFactoryMock.expectMake(std::nullopt, Ref(*sut), Ref(storageMock)) |
Wludzik, Jozef | bc766b4 | 2020-12-08 16:06:22 +0100 | [diff] [blame] | 396 | .Times(0); |
| 397 | |
Krzysztof Grobelny | a8182be | 2022-07-04 11:26:20 +0200 | [diff] [blame^] | 398 | auto [ec, path] = addReport({{"Name", reportParams.reportName()}, |
| 399 | {"ReportingType", "InvalidReportingType"}}); |
Karol Niczyj | 32859b6 | 2021-05-19 10:20:46 +0200 | [diff] [blame] | 400 | |
Wludzik, Jozef | bc766b4 | 2020-12-08 16:06:22 +0100 | [diff] [blame] | 401 | EXPECT_THAT(ec.value(), Eq(boost::system::errc::invalid_argument)); |
| 402 | EXPECT_THAT(path, Eq(std::string())); |
| 403 | } |
| 404 | |
Ankita Vilas Gawade | cd5b0b7 | 2022-01-20 20:55:04 +0000 | [diff] [blame] | 405 | TEST_F(TestReportManager, |
| 406 | DISABLED_failToAddReportWithMoreMetricPropertiesThanExpected) |
Wludzik, Jozef | bc766b4 | 2020-12-08 16:06:22 +0100 | [diff] [blame] | 407 | { |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 408 | reportFactoryMock.expectMake(std::nullopt, Ref(*sut), Ref(storageMock)) |
Wludzik, Jozef | bc766b4 | 2020-12-08 16:06:22 +0100 | [diff] [blame] | 409 | .Times(0); |
| 410 | |
Ankita Vilas Gawade | cd5b0b7 | 2022-01-20 20:55:04 +0000 | [diff] [blame] | 411 | reportParams.metricParameters( |
| 412 | std::vector<LabeledMetricParameters>{{LabeledMetricParameters{ |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 413 | {LabeledSensorInfo{"Service", |
| 414 | "/xyz/openbmc_project/sensors/power/p1", |
| 415 | "Metadata1"}}, |
Krzysztof Grobelny | 60fee07 | 2022-01-13 16:25:04 +0100 | [diff] [blame] | 416 | OperationType::avg, |
Ankita Vilas Gawade | cd5b0b7 | 2022-01-20 20:55:04 +0000 | [diff] [blame] | 417 | "MetricId1", |
| 418 | CollectionTimeScope::point, |
| 419 | CollectionDuration(Milliseconds(0u))}}}); |
| 420 | |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 421 | auto metricParams = reportParams.metricParameters(); |
Ankita Vilas Gawade | cd5b0b7 | 2022-01-20 20:55:04 +0000 | [diff] [blame] | 422 | auto& metricParamsVec = |
| 423 | metricParams[0].at_label<utils::tstring::SensorPath>(); |
| 424 | |
| 425 | for (size_t i = 0; i < ReportManager::maxNumberMetrics; i++) |
Wludzik, Jozef | bc766b4 | 2020-12-08 16:06:22 +0100 | [diff] [blame] | 426 | { |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 427 | metricParamsVec.emplace_back(LabeledSensorInfo{ |
Ankita Vilas Gawade | cd5b0b7 | 2022-01-20 20:55:04 +0000 | [diff] [blame] | 428 | "Service", "/xyz/openbmc_project/sensors/power/p1", "Metadata1"}); |
Wludzik, Jozef | bc766b4 | 2020-12-08 16:06:22 +0100 | [diff] [blame] | 429 | } |
Ankita Vilas Gawade | cd5b0b7 | 2022-01-20 20:55:04 +0000 | [diff] [blame] | 430 | |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 431 | reportParams.metricParameters(std::move(metricParams)); |
Wludzik, Jozef | bc766b4 | 2020-12-08 16:06:22 +0100 | [diff] [blame] | 432 | |
| 433 | auto [ec, path] = addReport(reportParams); |
Karol Niczyj | 32859b6 | 2021-05-19 10:20:46 +0200 | [diff] [blame] | 434 | |
Wludzik, Jozef | bc766b4 | 2020-12-08 16:06:22 +0100 | [diff] [blame] | 435 | EXPECT_THAT(ec.value(), Eq(boost::system::errc::argument_list_too_long)); |
| 436 | EXPECT_THAT(path, Eq(std::string())); |
| 437 | } |
| 438 | |
Ankita Vilas Gawade | cd5b0b7 | 2022-01-20 20:55:04 +0000 | [diff] [blame] | 439 | TEST_F(TestReportManager, DISABLED_failToAddReportWithMoreMetricsThanExpected) |
| 440 | { |
| 441 | reportFactoryMock.expectMake(std::nullopt, Ref(*sut), Ref(storageMock)) |
| 442 | .Times(0); |
| 443 | |
| 444 | auto metricParams = std::vector<LabeledMetricParameters>{}; |
| 445 | |
| 446 | for (size_t i = 0; i < ReportManager::maxNumberMetrics + 1; i++) |
| 447 | { |
| 448 | metricParams.emplace_back( |
| 449 | LabeledMetricParameters{{}, |
Krzysztof Grobelny | 60fee07 | 2022-01-13 16:25:04 +0100 | [diff] [blame] | 450 | OperationType::avg, |
Ankita Vilas Gawade | cd5b0b7 | 2022-01-20 20:55:04 +0000 | [diff] [blame] | 451 | "MetricId1", |
| 452 | CollectionTimeScope::point, |
| 453 | CollectionDuration(Milliseconds(0u))}); |
| 454 | } |
| 455 | |
| 456 | reportParams.metricParameters(std::move(metricParams)); |
| 457 | |
| 458 | auto [ec, path] = addReport(reportParams); |
| 459 | |
| 460 | EXPECT_THAT(ec.value(), Eq(boost::system::errc::argument_list_too_long)); |
| 461 | EXPECT_THAT(path, Eq(std::string())); |
| 462 | } |
| 463 | |
| 464 | TEST_F(TestReportManager, DISABLED_failToAddReportWithAppendLimitGreaterThanMax) |
| 465 | { |
| 466 | reportFactoryMock.expectMake(std::nullopt, Ref(*sut), Ref(storageMock)) |
| 467 | .Times(0); |
| 468 | |
| 469 | reportParams.appendLimit(ReportManager::maxAppendLimit + 1); |
| 470 | |
| 471 | auto [ec, path] = addReport(reportParams); |
| 472 | |
| 473 | EXPECT_THAT(ec.value(), Eq(boost::system::errc::invalid_argument)); |
| 474 | EXPECT_THAT(path, Eq(std::string())); |
| 475 | } |
| 476 | |
Krzysztof Grobelny | e6c417c | 2022-02-02 17:25:53 +0100 | [diff] [blame] | 477 | TEST_F(TestReportManager, addReportWithAppendLimitEqualToUint64MaxIsAllowed) |
| 478 | { |
| 479 | reportParams.appendLimit(std::numeric_limits<uint64_t>::max()); |
| 480 | |
| 481 | EXPECT_CALL(reportFactoryMock, convertMetricParams(_, _)); |
| 482 | reportFactoryMock.expectMake(reportParams, Ref(*sut), Ref(storageMock)) |
| 483 | .WillOnce(Return(ByMove(std::move(reportMockPtr)))); |
| 484 | |
| 485 | auto [ec, path] = addReport(reportParams); |
| 486 | EXPECT_THAT(ec.value(), Eq(boost::system::errc::success)); |
| 487 | EXPECT_THAT(path, Eq(reportMock.getPath())); |
| 488 | } |
| 489 | |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 490 | TEST_F(TestReportManager, DISABLED_failToAddReportWhenMaxReportIsReached) |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 491 | { |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 492 | reportFactoryMock.expectMake(std::nullopt, Ref(*sut), Ref(storageMock)) |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 493 | .Times(ReportManager::maxReports); |
| 494 | |
| 495 | for (size_t i = 0; i < ReportManager::maxReports; i++) |
| 496 | { |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 497 | reportParams.reportId(reportParams.reportName() + std::to_string(i)); |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 498 | |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 499 | auto [ec, path] = addReport(reportParams); |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 500 | EXPECT_THAT(ec.value(), Eq(boost::system::errc::success)); |
| 501 | } |
| 502 | |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 503 | reportParams.reportId(reportParams.reportName() + |
| 504 | std::to_string(ReportManager::maxReports)); |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 505 | auto [ec, path] = addReport(reportParams); |
Karol Niczyj | 32859b6 | 2021-05-19 10:20:46 +0200 | [diff] [blame] | 506 | |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 507 | EXPECT_THAT(ec.value(), Eq(boost::system::errc::too_many_files_open)); |
| 508 | EXPECT_THAT(path, Eq(std::string())); |
| 509 | } |
| 510 | |
| 511 | TEST_F(TestReportManager, removeReport) |
| 512 | { |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 513 | { |
| 514 | InSequence seq; |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 515 | EXPECT_CALL(reportFactoryMock, convertMetricParams(_, _)); |
| 516 | reportFactoryMock.expectMake(reportParams, Ref(*sut), Ref(storageMock)) |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 517 | .WillOnce(Return(ByMove(std::move(reportMockPtr)))); |
| 518 | EXPECT_CALL(reportMock, Die()); |
| 519 | EXPECT_CALL(checkPoint, Call("end")); |
| 520 | } |
| 521 | |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 522 | addReport(reportParams); |
| 523 | sut->removeReport(&reportMock); |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 524 | checkPoint.Call("end"); |
| 525 | } |
| 526 | |
| 527 | TEST_F(TestReportManager, removingReportThatIsNotInContainerHasNoEffect) |
| 528 | { |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 529 | { |
| 530 | InSequence seq; |
| 531 | EXPECT_CALL(checkPoint, Call("end")); |
| 532 | EXPECT_CALL(reportMock, Die()); |
| 533 | } |
| 534 | |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 535 | sut->removeReport(&reportMock); |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 536 | checkPoint.Call("end"); |
| 537 | } |
| 538 | |
| 539 | TEST_F(TestReportManager, removingSameReportTwiceHasNoSideEffect) |
| 540 | { |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 541 | { |
| 542 | InSequence seq; |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 543 | EXPECT_CALL(reportFactoryMock, convertMetricParams(_, _)); |
| 544 | reportFactoryMock.expectMake(reportParams, Ref(*sut), Ref(storageMock)) |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 545 | .WillOnce(Return(ByMove(std::move(reportMockPtr)))); |
| 546 | EXPECT_CALL(reportMock, Die()); |
| 547 | EXPECT_CALL(checkPoint, Call("end")); |
| 548 | } |
| 549 | |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 550 | addReport(reportParams); |
| 551 | sut->removeReport(&reportMock); |
| 552 | sut->removeReport(&reportMock); |
Wludzik, Jozef | 2f9f9b8 | 2020-10-13 09:07:45 +0200 | [diff] [blame] | 553 | checkPoint.Call("end"); |
| 554 | } |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 555 | |
Krzysztof Grobelny | e8fc575 | 2021-02-05 14:30:45 +0000 | [diff] [blame] | 556 | class TestReportManagerWithAggregationOperationType : |
| 557 | public TestReportManager, |
| 558 | public WithParamInterface<OperationType> |
| 559 | { |
| 560 | public: |
| 561 | OperationType operationType = GetParam(); |
| 562 | }; |
| 563 | |
| 564 | INSTANTIATE_TEST_SUITE_P(_, TestReportManagerWithAggregationOperationType, |
Krzysztof Grobelny | 60fee07 | 2022-01-13 16:25:04 +0100 | [diff] [blame] | 565 | Values(OperationType::max, OperationType::min, |
| 566 | OperationType::avg, OperationType::sum)); |
Krzysztof Grobelny | e8fc575 | 2021-02-05 14:30:45 +0000 | [diff] [blame] | 567 | |
| 568 | TEST_P(TestReportManagerWithAggregationOperationType, |
| 569 | addReportWithDifferentOperationTypes) |
| 570 | { |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 571 | reportParams.metricParameters( |
| 572 | std::vector<LabeledMetricParameters>{{LabeledMetricParameters{ |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 573 | {LabeledSensorInfo{"Service", |
| 574 | "/xyz/openbmc_project/sensors/power/p1", |
| 575 | "Metadata1"}}, |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 576 | operationType, |
| 577 | "MetricId1", |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 578 | CollectionTimeScope::point, |
| 579 | CollectionDuration(Milliseconds(0u))}}}); |
Krzysztof Grobelny | e8fc575 | 2021-02-05 14:30:45 +0000 | [diff] [blame] | 580 | |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 581 | reportFactoryMock.expectMake(reportParams, Ref(*sut), Ref(storageMock)) |
Krzysztof Grobelny | e8fc575 | 2021-02-05 14:30:45 +0000 | [diff] [blame] | 582 | .WillOnce(Return(ByMove(std::move(reportMockPtr)))); |
| 583 | |
| 584 | auto [ec, path] = addReport(reportParams); |
Karol Niczyj | 32859b6 | 2021-05-19 10:20:46 +0200 | [diff] [blame] | 585 | |
Krzysztof Grobelny | e8fc575 | 2021-02-05 14:30:45 +0000 | [diff] [blame] | 586 | EXPECT_THAT(ec.value(), Eq(boost::system::errc::success)); |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 587 | EXPECT_THAT(path, Eq("/"s + reportParams.reportId())); |
Krzysztof Grobelny | e8fc575 | 2021-02-05 14:30:45 +0000 | [diff] [blame] | 588 | } |
| 589 | |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 590 | class TestReportManagerStorage : public TestReportManager |
| 591 | { |
| 592 | public: |
| 593 | using FilePath = interfaces::JsonStorage::FilePath; |
| 594 | using DirectoryPath = interfaces::JsonStorage::DirectoryPath; |
| 595 | |
| 596 | void SetUp() override |
| 597 | { |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 598 | EXPECT_CALL(reportFactoryMock, convertMetricParams(_, _)).Times(0); |
| 599 | |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 600 | ON_CALL(storageMock, list()) |
| 601 | .WillByDefault(Return(std::vector<FilePath>{FilePath("report1")})); |
| 602 | ON_CALL(storageMock, load(FilePath("report1"))) |
Krzysztof Grobelny | 6ccfcbf | 2020-11-04 09:31:36 +0100 | [diff] [blame] | 603 | .WillByDefault(InvokeWithoutArgs([this] { return data; })); |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 604 | } |
| 605 | |
| 606 | void makeReportManager() |
| 607 | { |
Krzysztof Grobelny | e6d4887 | 2022-02-08 13:41:30 +0100 | [diff] [blame] | 608 | sut = std::make_unique<ReportManager>(std::move(reportFactoryMockPtr), |
| 609 | std::move(storageMockPtr), |
| 610 | DbusEnvironment::getObjServer()); |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | nlohmann::json data = nlohmann::json{ |
Lukasz Kazmierczak | 7e098e9 | 2021-09-16 15:59:56 +0200 | [diff] [blame] | 614 | {"Enabled", reportParams.enabled()}, |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 615 | {"Version", Report::reportVersion}, |
Krzysztof Grobelny | b8cc78d | 2021-11-29 15:54:53 +0100 | [diff] [blame] | 616 | {"Id", reportParams.reportId()}, |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 617 | {"Name", reportParams.reportName()}, |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 618 | {"ReportingType", utils::toUnderlying(reportParams.reportingType())}, |
| 619 | {"ReportActions", reportParams.reportActions()}, |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 620 | {"Interval", reportParams.interval().count()}, |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 621 | {"ReportUpdates", utils::toUnderlying(reportParams.reportUpdates())}, |
Szymon Dompke | 3eb5686 | 2021-09-20 15:32:04 +0200 | [diff] [blame] | 622 | {"AppendLimit", reportParams.appendLimit()}, |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 623 | {"ReadingParameters", reportParams.metricParameters()}}; |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 624 | }; |
| 625 | |
| 626 | TEST_F(TestReportManagerStorage, reportManagerCtorAddReportFromStorage) |
| 627 | { |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 628 | reportFactoryMock.expectMake(reportParams, _, Ref(storageMock)); |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 629 | |
| 630 | makeReportManager(); |
| 631 | } |
| 632 | |
| 633 | TEST_F(TestReportManagerStorage, |
| 634 | reportManagerCtorRemoveFileIfVersionDoesNotMatch) |
| 635 | { |
| 636 | data["Version"] = Report::reportVersion - 1; |
| 637 | |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 638 | EXPECT_CALL(storageMock, remove(FilePath("report1"))); |
| 639 | |
| 640 | makeReportManager(); |
| 641 | } |
| 642 | |
| 643 | TEST_F(TestReportManagerStorage, |
| 644 | reportManagerCtorRemoveFileIfIntervalHasWrongType) |
| 645 | { |
| 646 | data["Interval"] = "1000"; |
| 647 | |
Wludzik, Jozef | e236279 | 2020-10-27 17:23:55 +0100 | [diff] [blame] | 648 | EXPECT_CALL(storageMock, remove(FilePath("report1"))); |
| 649 | |
| 650 | makeReportManager(); |
| 651 | } |