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