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 | |
Willy Tu | 99d292a | 2022-02-08 17:40:58 -0800 | [diff] [blame] | 12 | static HandlerConfig<VersionBlobHandler::ActionPack> |
| 13 | createMockVersionConfig(const std::string& id, |
| 14 | ImageHandlerMock** im = nullptr, |
| 15 | TriggerMock** tm = nullptr) |
William A. Kennington III | abf1735 | 2020-12-22 21:07:11 -0800 | [diff] [blame] | 16 | { |
| 17 | HandlerConfig<VersionBlobHandler::ActionPack> ret; |
| 18 | ret.blobId = id; |
| 19 | auto handler = std::make_unique<testing::StrictMock<ImageHandlerMock>>(); |
| 20 | if (im != nullptr) |
| 21 | { |
| 22 | *im = handler.get(); |
| 23 | } |
| 24 | ret.handler = std::move(handler); |
| 25 | ret.actions = std::make_unique<VersionBlobHandler::ActionPack>(); |
| 26 | auto trigger = std::make_unique<testing::StrictMock<TriggerMock>>(); |
| 27 | if (tm != nullptr) |
| 28 | { |
| 29 | *tm = trigger.get(); |
| 30 | } |
| 31 | ret.actions->onOpen = std::move(trigger); |
| 32 | return ret; |
| 33 | } |
| 34 | |
| 35 | template <typename C, typename Im = std::map<std::string, ImageHandlerMock*>, |
| 36 | typename Tm = std::map<std::string, TriggerMock*>> |
Willy Tu | 99d292a | 2022-02-08 17:40:58 -0800 | [diff] [blame] | 37 | static std::vector<HandlerConfig<VersionBlobHandler::ActionPack>> |
| 38 | createMockVersionConfigs(const C& ids, Im* im = nullptr, Tm* tm = nullptr) |
William A. Kennington III | abf1735 | 2020-12-22 21:07:11 -0800 | [diff] [blame] | 39 | { |
| 40 | std::vector<HandlerConfig<VersionBlobHandler::ActionPack>> ret; |
Willy Tu | 99d292a | 2022-02-08 17:40:58 -0800 | [diff] [blame] | 41 | ret.reserve(ids.size()); |
| 42 | std::for_each(ids.begin(), ids.end(), [im, tm, &ret](const auto& id) { |
| 43 | ret.emplace_back( |
William A. Kennington III | abf1735 | 2020-12-22 21:07:11 -0800 | [diff] [blame] | 44 | createMockVersionConfig(id, im == nullptr ? nullptr : &(*im)[id], |
| 45 | tm == nullptr ? nullptr : &(*tm)[id])); |
Willy Tu | 99d292a | 2022-02-08 17:40:58 -0800 | [diff] [blame] | 46 | }); |
William A. Kennington III | abf1735 | 2020-12-22 21:07:11 -0800 | [diff] [blame] | 47 | return ret; |
| 48 | } |
| 49 | |
| 50 | } // namespace ipmi_flash |