blob: 9fa2f4821ecd6bb649f02459343d01e79d73dacb [file] [log] [blame]
Wludzik, Jozef76833cb2020-12-21 14:42:41 +01001#pragma once
2
3#include "interfaces/trigger_factory.hpp"
4#include "mocks/trigger_mock.hpp"
5#include "params/trigger_params.hpp"
Cezary Zwolak4416fce2021-03-17 03:21:06 +01006#include "trigger.hpp"
7#include "utils/conversion_trigger.hpp"
Wludzik, Jozef76833cb2020-12-21 14:42:41 +01008
9#include <gmock/gmock.h>
10
11class TriggerFactoryMock : public interfaces::TriggerFactory
12{
13 public:
14 TriggerFactoryMock()
15 {
16 using namespace testing;
17
Szymon Dompkee28aa532021-10-27 12:33:12 +020018 ON_CALL(*this, make(A<const std::string&>(), _, _, _, _, _, _, _))
19 .WillByDefault(WithArgs<0>(Invoke([](const std::string& id) {
20 return std::make_unique<NiceMock<TriggerMock>>(id);
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010021 })));
22 }
23
Cezary Zwolak4416fce2021-03-17 03:21:06 +010024 MOCK_METHOD(std::unique_ptr<interfaces::Trigger>, make,
Szymon Dompkee28aa532021-10-27 12:33:12 +020025 (const std::string& id, const std::string& name,
Szymon Dompke20013012021-07-23 09:54:20 +020026 const std::vector<std::string>& triggerActions,
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010027 const std::vector<std::string>& reportIds,
Cezary Zwolak4416fce2021-03-17 03:21:06 +010028 interfaces::TriggerManager& triggerManager,
29 interfaces::JsonStorage& triggerStorage,
30 const LabeledTriggerThresholdParams& labeledThresholdParams,
31 const std::vector<LabeledSensorInfo>& labeledSensorsInfo),
32 (const, override));
33
34 MOCK_METHOD(std::vector<LabeledSensorInfo>, getLabeledSensorsInfo,
35 (boost::asio::yield_context&, const SensorsInfo&),
36 (const, override));
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010037
38 auto& expectMake(
Cezary Zwolak4416fce2021-03-17 03:21:06 +010039 std::optional<TriggerParams> paramsOpt,
Cezary Zwolaka4e67612021-02-18 13:16:16 +010040 const testing::Matcher<interfaces::TriggerManager&>& tm,
41 const testing::Matcher<interfaces::JsonStorage&>& triggerStorage)
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010042 {
Wludzik, Jozef1477fe62021-01-02 11:56:10 +010043 using namespace testing;
44
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010045 if (paramsOpt)
46 {
47 const TriggerParams& params = *paramsOpt;
Cezary Zwolak4416fce2021-03-17 03:21:06 +010048
49 const auto sensorInfos =
50 utils::fromLabeledSensorsInfo(params.sensors());
51
52 ON_CALL(*this, getLabeledSensorsInfo(_, sensorInfos))
53 .WillByDefault(Return(params.sensors()));
54
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010055 return EXPECT_CALL(
Szymon Dompkee28aa532021-10-27 12:33:12 +020056 *this, make(params.id(), params.name(), params.triggerActions(),
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010057 params.reportIds(), tm, triggerStorage,
Szymon Dompke20013012021-07-23 09:54:20 +020058 params.thresholdParams(), params.sensors()));
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010059 }
60 else
61 {
Cezary Zwolak4416fce2021-03-17 03:21:06 +010062 const std::vector<LabeledSensorInfo> dummy = {
63 {"service99",
64 "/xyz/openbmc_project/sensors/temperature/BMC_Temp99",
65 "metadata99"}};
66
67 ON_CALL(*this, getLabeledSensorsInfo(_, _))
68 .WillByDefault(Return(dummy));
69
Szymon Dompke20013012021-07-23 09:54:20 +020070 return EXPECT_CALL(*this,
Szymon Dompkee28aa532021-10-27 12:33:12 +020071 make(_, _, _, _, tm, triggerStorage, _, dummy));
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010072 }
73 }
74};