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