Willy Tu | 99d292a | 2022-02-08 17:40:58 -0800 | [diff] [blame] | 1 | #pragma once |
William A. Kennington III | cc7f385 | 2021-01-21 19:01:56 -0800 | [diff] [blame] | 2 | #include "handler_config.hpp" |
William A. Kennington III | abf1735 | 2020-12-22 21:07:11 -0800 | [diff] [blame] | 3 | #include "image_mock.hpp" |
| 4 | #include "triggerable_mock.hpp" |
| 5 | #include "version_handler.hpp" |
| 6 | |
William A. Kennington III | abf1735 | 2020-12-22 21:07:11 -0800 | [diff] [blame] | 7 | #include <string> |
William A. Kennington III | abf1735 | 2020-12-22 21:07:11 -0800 | [diff] [blame] | 8 | |
| 9 | namespace ipmi_flash |
| 10 | { |
| 11 | |
Patrick Williams | 42a44c2 | 2024-08-16 15:21:32 -0400 | [diff] [blame^] | 12 | static HandlerConfig<VersionBlobHandler::ActionPack> createMockVersionConfig( |
| 13 | const std::string& id, ImageHandlerMock** im = nullptr, |
| 14 | TriggerMock** tm = nullptr) |
William A. Kennington III | abf1735 | 2020-12-22 21:07:11 -0800 | [diff] [blame] | 15 | { |
| 16 | HandlerConfig<VersionBlobHandler::ActionPack> ret; |
| 17 | ret.blobId = id; |
| 18 | auto handler = std::make_unique<testing::StrictMock<ImageHandlerMock>>(); |
| 19 | if (im != nullptr) |
| 20 | { |
| 21 | *im = handler.get(); |
| 22 | } |
| 23 | ret.handler = std::move(handler); |
| 24 | ret.actions = std::make_unique<VersionBlobHandler::ActionPack>(); |
| 25 | auto trigger = std::make_unique<testing::StrictMock<TriggerMock>>(); |
| 26 | if (tm != nullptr) |
| 27 | { |
| 28 | *tm = trigger.get(); |
| 29 | } |
| 30 | ret.actions->onOpen = std::move(trigger); |
| 31 | return ret; |
| 32 | } |
| 33 | |
| 34 | template <typename C, typename Im = std::map<std::string, ImageHandlerMock*>, |
| 35 | typename Tm = std::map<std::string, TriggerMock*>> |
Willy Tu | 99d292a | 2022-02-08 17:40:58 -0800 | [diff] [blame] | 36 | static std::vector<HandlerConfig<VersionBlobHandler::ActionPack>> |
| 37 | createMockVersionConfigs(const C& ids, Im* im = nullptr, Tm* tm = nullptr) |
William A. Kennington III | abf1735 | 2020-12-22 21:07:11 -0800 | [diff] [blame] | 38 | { |
| 39 | std::vector<HandlerConfig<VersionBlobHandler::ActionPack>> ret; |
Willy Tu | 99d292a | 2022-02-08 17:40:58 -0800 | [diff] [blame] | 40 | ret.reserve(ids.size()); |
| 41 | std::for_each(ids.begin(), ids.end(), [im, tm, &ret](const auto& id) { |
| 42 | ret.emplace_back( |
William A. Kennington III | abf1735 | 2020-12-22 21:07:11 -0800 | [diff] [blame] | 43 | createMockVersionConfig(id, im == nullptr ? nullptr : &(*im)[id], |
| 44 | tm == nullptr ? nullptr : &(*tm)[id])); |
Willy Tu | 99d292a | 2022-02-08 17:40:58 -0800 | [diff] [blame] | 45 | }); |
William A. Kennington III | abf1735 | 2020-12-22 21:07:11 -0800 | [diff] [blame] | 46 | return ret; |
| 47 | } |
| 48 | |
| 49 | } // namespace ipmi_flash |