1*a49a3f79SGaurav Gandhi // Copyright 2021 Google Inc.
2*a49a3f79SGaurav Gandhi //
3*a49a3f79SGaurav Gandhi // Licensed under the Apache License, Version 2.0 (the "License");
4*a49a3f79SGaurav Gandhi // you may not use this file except in compliance with the License.
5*a49a3f79SGaurav Gandhi // You may obtain a copy of the License at
6*a49a3f79SGaurav Gandhi //
7*a49a3f79SGaurav Gandhi // http://www.apache.org/licenses/LICENSE-2.0
8*a49a3f79SGaurav Gandhi //
9*a49a3f79SGaurav Gandhi // Unless required by applicable law or agreed to in writing, software
10*a49a3f79SGaurav Gandhi // distributed under the License is distributed on an "AS IS" BASIS,
11*a49a3f79SGaurav Gandhi // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12*a49a3f79SGaurav Gandhi // See the License for the specific language governing permissions and
13*a49a3f79SGaurav Gandhi // limitations under the License.
14*a49a3f79SGaurav Gandhi
15*a49a3f79SGaurav Gandhi #include "handler_config.hpp"
16*a49a3f79SGaurav Gandhi #include "image_mock.hpp"
17*a49a3f79SGaurav Gandhi #include "log_handler.hpp"
18*a49a3f79SGaurav Gandhi #include "triggerable_mock.hpp"
19*a49a3f79SGaurav Gandhi
20*a49a3f79SGaurav Gandhi #include <memory>
21*a49a3f79SGaurav Gandhi #include <string>
22*a49a3f79SGaurav Gandhi #include <utility>
23*a49a3f79SGaurav Gandhi
24*a49a3f79SGaurav Gandhi namespace ipmi_flash
25*a49a3f79SGaurav Gandhi {
26*a49a3f79SGaurav Gandhi
createMockLogConfig(const std::string & id,ImageHandlerMock ** im=nullptr,TriggerMock ** tm=nullptr)27*a49a3f79SGaurav Gandhi auto createMockLogConfig(const std::string& id, ImageHandlerMock** im = nullptr,
28*a49a3f79SGaurav Gandhi TriggerMock** tm = nullptr)
29*a49a3f79SGaurav Gandhi {
30*a49a3f79SGaurav Gandhi HandlerConfig<LogBlobHandler::ActionPack> ret;
31*a49a3f79SGaurav Gandhi ret.blobId = id;
32*a49a3f79SGaurav Gandhi auto handler = std::make_unique<testing::StrictMock<ImageHandlerMock>>();
33*a49a3f79SGaurav Gandhi if (im != nullptr)
34*a49a3f79SGaurav Gandhi {
35*a49a3f79SGaurav Gandhi *im = handler.get();
36*a49a3f79SGaurav Gandhi }
37*a49a3f79SGaurav Gandhi ret.handler = std::move(handler);
38*a49a3f79SGaurav Gandhi ret.actions = std::make_unique<LogBlobHandler::ActionPack>();
39*a49a3f79SGaurav Gandhi auto trigger = std::make_unique<testing::StrictMock<TriggerMock>>();
40*a49a3f79SGaurav Gandhi if (tm != nullptr)
41*a49a3f79SGaurav Gandhi {
42*a49a3f79SGaurav Gandhi *tm = trigger.get();
43*a49a3f79SGaurav Gandhi }
44*a49a3f79SGaurav Gandhi ret.actions->onOpen = std::move(trigger);
45*a49a3f79SGaurav Gandhi return ret;
46*a49a3f79SGaurav Gandhi }
47*a49a3f79SGaurav Gandhi
48*a49a3f79SGaurav Gandhi template <typename C, typename Im = std::map<std::string, ImageHandlerMock*>,
49*a49a3f79SGaurav Gandhi typename Tm = std::map<std::string, TriggerMock*>>
createMockLogConfigs(const C & ids,Im * im=nullptr,Tm * tm=nullptr)50*a49a3f79SGaurav Gandhi auto createMockLogConfigs(const C& ids, Im* im = nullptr, Tm* tm = nullptr)
51*a49a3f79SGaurav Gandhi {
52*a49a3f79SGaurav Gandhi std::vector<HandlerConfig<LogBlobHandler::ActionPack>> ret;
53*a49a3f79SGaurav Gandhi for (const auto& id : ids)
54*a49a3f79SGaurav Gandhi {
55*a49a3f79SGaurav Gandhi ret.push_back(
56*a49a3f79SGaurav Gandhi createMockLogConfig(id, im == nullptr ? nullptr : &(*im)[id],
57*a49a3f79SGaurav Gandhi tm == nullptr ? nullptr : &(*tm)[id]));
58*a49a3f79SGaurav Gandhi }
59*a49a3f79SGaurav Gandhi return ret;
60*a49a3f79SGaurav Gandhi }
61*a49a3f79SGaurav Gandhi } // namespace ipmi_flash
62