blob: 71fabaf392410a57a1abcda228ee4970b3b454f4 [file] [log] [blame]
Willy Tu99d292a2022-02-08 17:40:58 -08001#pragma once
William A. Kennington IIIcc7f3852021-01-21 19:01:56 -08002#include "handler_config.hpp"
William A. Kennington IIIabf17352020-12-22 21:07:11 -08003#include "image_mock.hpp"
4#include "triggerable_mock.hpp"
5#include "version_handler.hpp"
6
William A. Kennington IIIabf17352020-12-22 21:07:11 -08007#include <string>
William A. Kennington IIIabf17352020-12-22 21:07:11 -08008
9namespace ipmi_flash
10{
11
Patrick Williams42a44c22024-08-16 15:21:32 -040012static HandlerConfig<VersionBlobHandler::ActionPack> createMockVersionConfig(
13 const std::string& id, ImageHandlerMock** im = nullptr,
14 TriggerMock** tm = nullptr)
William A. Kennington IIIabf17352020-12-22 21:07:11 -080015{
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
34template <typename C, typename Im = std::map<std::string, ImageHandlerMock*>,
35 typename Tm = std::map<std::string, TriggerMock*>>
Willy Tu99d292a2022-02-08 17:40:58 -080036static std::vector<HandlerConfig<VersionBlobHandler::ActionPack>>
37 createMockVersionConfigs(const C& ids, Im* im = nullptr, Tm* tm = nullptr)
William A. Kennington IIIabf17352020-12-22 21:07:11 -080038{
39 std::vector<HandlerConfig<VersionBlobHandler::ActionPack>> ret;
Willy Tu99d292a2022-02-08 17:40:58 -080040 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 IIIabf17352020-12-22 21:07:11 -080043 createMockVersionConfig(id, im == nullptr ? nullptr : &(*im)[id],
44 tm == nullptr ? nullptr : &(*tm)[id]));
Willy Tu99d292a2022-02-08 17:40:58 -080045 });
William A. Kennington IIIabf17352020-12-22 21:07:11 -080046 return ret;
47}
48
49} // namespace ipmi_flash