blob: 3682a46280c5291f3b178439b14be99dd3c30c5c [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
Cezary Zwolak4416fce2021-03-17 03:21:06 +010018 ON_CALL(*this, make(A<const std::string&>(), _, _, _, _, _, _, _, _, _))
19 .WillByDefault(WithArgs<0>(Invoke([](const std::string& name) {
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010020 return std::make_unique<NiceMock<TriggerMock>>(name);
21 })));
22 }
23
Cezary Zwolak4416fce2021-03-17 03:21:06 +010024 MOCK_METHOD(std::unique_ptr<interfaces::Trigger>, make,
25 (const std::string& name, bool isDiscrete, bool logToJournal,
26 bool logToRedfish, bool updateReport,
27 const std::vector<std::string>& reportNames,
28 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(
Cezary Zwolak4416fce2021-03-17 03:21:06 +010056 *this,
57 make(params.name(), params.isDiscrete(), params.logToJournal(),
58 params.logToRedfish(), params.updateReport(),
59 params.reportNames(), tm, triggerStorage,
60 params.thresholdParams(), params.sensors()));
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010061 }
62 else
63 {
Cezary Zwolak4416fce2021-03-17 03:21:06 +010064 const std::vector<LabeledSensorInfo> dummy = {
65 {"service99",
66 "/xyz/openbmc_project/sensors/temperature/BMC_Temp99",
67 "metadata99"}};
68
69 ON_CALL(*this, getLabeledSensorsInfo(_, _))
70 .WillByDefault(Return(dummy));
71
Cezary Zwolaka4e67612021-02-18 13:16:16 +010072 return EXPECT_CALL(
Cezary Zwolak4416fce2021-03-17 03:21:06 +010073 *this, make(_, _, _, _, _, _, tm, triggerStorage, _, dummy));
Wludzik, Jozef76833cb2020-12-21 14:42:41 +010074 }
75 }
76};