blob: a733ca42b6ba0c0576ba0dbaab57e09d6b9870ad [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"
Szymon Dompke94f71c52021-12-10 07:16:33 +01008#include "utils/transform.hpp"
Wludzik, Jozef76833cb2020-12-21 14:42:41 +01009
10#include <gmock/gmock.h>
11
12class TriggerFactoryMock : public interfaces::TriggerFactory
13{
14 public:
15 TriggerFactoryMock()
16 {
17 using namespace testing;
18
Szymon Dompkee28aa532021-10-27 12:33:12 +020019 ON_CALL(*this, make(A<const std::string&>(), _, _, _, _, _, _, _))
20 .WillByDefault(WithArgs<0>(Invoke([](const std::string& id) {
Patrick Williamsc7935fa2023-10-20 11:19:30 -050021 return std::make_unique<NiceMock<TriggerMock>>(id);
22 })));
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010023 }
24
Cezary Zwolak4416fce2021-03-17 03:21:06 +010025 MOCK_METHOD(std::unique_ptr<interfaces::Trigger>, make,
Szymon Dompkee28aa532021-10-27 12:33:12 +020026 (const std::string& id, const std::string& name,
Szymon Dompke20013012021-07-23 09:54:20 +020027 const std::vector<std::string>& triggerActions,
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010028 const std::vector<std::string>& reportIds,
Cezary Zwolak4416fce2021-03-17 03:21:06 +010029 interfaces::TriggerManager& triggerManager,
30 interfaces::JsonStorage& triggerStorage,
31 const LabeledTriggerThresholdParams& labeledThresholdParams,
32 const std::vector<LabeledSensorInfo>& labeledSensorsInfo),
33 (const, override));
34
35 MOCK_METHOD(std::vector<LabeledSensorInfo>, getLabeledSensorsInfo,
36 (boost::asio::yield_context&, const SensorsInfo&),
37 (const, override));
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010038
Szymon Dompke94f71c52021-12-10 07:16:33 +010039 MOCK_METHOD(std::vector<LabeledSensorInfo>, getLabeledSensorsInfo,
40 (const SensorsInfo&), (const, override));
41
42 MOCK_METHOD(void, updateThresholds,
43 (std::vector<std::shared_ptr<interfaces::Threshold>> &
44 currentThresholds,
Szymon Dompkeb7b7e1b2022-05-19 10:15:48 +020045 const std::string& triggerId,
Szymon Dompke94f71c52021-12-10 07:16:33 +010046 const std::vector<TriggerAction>& triggerActions,
47 const std::shared_ptr<std::vector<std::string>>& reportIds,
48 const Sensors& sensors,
49 const LabeledTriggerThresholdParams& newParams),
50 (const, override));
51
52 MOCK_METHOD(void, updateSensors,
53 (Sensors & currentSensors,
54 const std::vector<LabeledSensorInfo>& senorParams),
55 (const, override));
56
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010057 auto& expectMake(
Cezary Zwolak4416fce2021-03-17 03:21:06 +010058 std::optional<TriggerParams> paramsOpt,
Cezary Zwolaka4e67612021-02-18 13:16:16 +010059 const testing::Matcher<interfaces::TriggerManager&>& tm,
60 const testing::Matcher<interfaces::JsonStorage&>& triggerStorage)
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010061 {
Wludzik, Jozef1477fe62021-01-02 11:56:10 +010062 using namespace testing;
63
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010064 if (paramsOpt)
65 {
66 const TriggerParams& params = *paramsOpt;
Cezary Zwolak4416fce2021-03-17 03:21:06 +010067
68 const auto sensorInfos =
69 utils::fromLabeledSensorsInfo(params.sensors());
70
71 ON_CALL(*this, getLabeledSensorsInfo(_, sensorInfos))
72 .WillByDefault(Return(params.sensors()));
73
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010074 return EXPECT_CALL(
Szymon Dompke94f71c52021-12-10 07:16:33 +010075 *this, make(params.id(), params.name(),
Patrick Williamsc7935fa2023-10-20 11:19:30 -050076 utils::transform(params.triggerActions(),
77 [](const auto& action) {
Patrick Williams3a1c2972023-05-10 07:51:04 -050078 return actionToString(action);
Patrick Williamsc7935fa2023-10-20 11:19:30 -050079 }),
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010080 params.reportIds(), tm, triggerStorage,
Szymon Dompke20013012021-07-23 09:54:20 +020081 params.thresholdParams(), params.sensors()));
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010082 }
83 else
84 {
Cezary Zwolak4416fce2021-03-17 03:21:06 +010085 const std::vector<LabeledSensorInfo> dummy = {
86 {"service99",
87 "/xyz/openbmc_project/sensors/temperature/BMC_Temp99",
88 "metadata99"}};
89
90 ON_CALL(*this, getLabeledSensorsInfo(_, _))
91 .WillByDefault(Return(dummy));
92
Szymon Dompke20013012021-07-23 09:54:20 +020093 return EXPECT_CALL(*this,
Szymon Dompkee28aa532021-10-27 12:33:12 +020094 make(_, _, _, _, tm, triggerStorage, _, dummy));
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010095 }
96 }
97};