blob: d8035a51f9f6c896ad30373774be8ad1213f4f16 [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
Willy Tu99d292a2022-02-08 17:40:58 -080012static HandlerConfig<VersionBlobHandler::ActionPack>
13 createMockVersionConfig(const std::string& id,
14 ImageHandlerMock** im = nullptr,
15 TriggerMock** tm = nullptr)
William A. Kennington IIIabf17352020-12-22 21:07:11 -080016{
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
35template <typename C, typename Im = std::map<std::string, ImageHandlerMock*>,
36 typename Tm = std::map<std::string, TriggerMock*>>
Willy Tu99d292a2022-02-08 17:40:58 -080037static std::vector<HandlerConfig<VersionBlobHandler::ActionPack>>
38 createMockVersionConfigs(const C& ids, Im* im = nullptr, Tm* tm = nullptr)
William A. Kennington IIIabf17352020-12-22 21:07:11 -080039{
40 std::vector<HandlerConfig<VersionBlobHandler::ActionPack>> ret;
Willy Tu99d292a2022-02-08 17:40:58 -080041 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 IIIabf17352020-12-22 21:07:11 -080044 createMockVersionConfig(id, im == nullptr ? nullptr : &(*im)[id],
45 tm == nullptr ? nullptr : &(*tm)[id]));
Willy Tu99d292a2022-02-08 17:40:58 -080046 });
William A. Kennington IIIabf17352020-12-22 21:07:11 -080047 return ret;
48}
49
50} // namespace ipmi_flash