1 #pragma once 2 #include "handler_config.hpp" 3 #include "image_mock.hpp" 4 #include "triggerable_mock.hpp" 5 #include "version_handler.hpp" 6 7 #include <string> 8 9 namespace ipmi_flash 10 { 11 12 static HandlerConfig<VersionBlobHandler::ActionPack> 13 createMockVersionConfig(const std::string& id, 14 ImageHandlerMock** im = nullptr, 15 TriggerMock** tm = nullptr) 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*>> 37 static std::vector<HandlerConfig<VersionBlobHandler::ActionPack>> 38 createMockVersionConfigs(const C& ids, Im* im = nullptr, Tm* tm = nullptr) 39 { 40 std::vector<HandlerConfig<VersionBlobHandler::ActionPack>> ret; 41 ret.reserve(ids.size()); 42 std::for_each(ids.begin(), ids.end(), [im, tm, &ret](const auto& id) { 43 ret.emplace_back( 44 createMockVersionConfig(id, im == nullptr ? nullptr : &(*im)[id], 45 tm == nullptr ? nullptr : &(*tm)[id])); 46 }); 47 return ret; 48 } 49 50 } // namespace ipmi_flash 51