1 #pragma once 2 3 #include "interfaces/trigger_factory.hpp" 4 #include "mocks/trigger_mock.hpp" 5 #include "params/trigger_params.hpp" 6 #include "trigger.hpp" 7 #include "utils/conversion_trigger.hpp" 8 #include "utils/transform.hpp" 9 10 #include <gmock/gmock.h> 11 12 class TriggerFactoryMock : public interfaces::TriggerFactory 13 { 14 public: 15 TriggerFactoryMock() 16 { 17 using namespace testing; 18 19 ON_CALL(*this, make(A<const std::string&>(), _, _, _, _, _, _, _)) 20 .WillByDefault(WithArgs<0>(Invoke([](const std::string& id) { 21 return std::make_unique<NiceMock<TriggerMock>>(id); 22 }))); 23 } 24 25 MOCK_METHOD(std::unique_ptr<interfaces::Trigger>, make, 26 (const std::string& id, const std::string& name, 27 const std::vector<std::string>& triggerActions, 28 const std::vector<std::string>& reportIds, 29 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)); 38 39 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, 45 const std::vector<TriggerAction>& triggerActions, 46 const std::shared_ptr<std::vector<std::string>>& reportIds, 47 const Sensors& sensors, 48 const LabeledTriggerThresholdParams& newParams), 49 (const, override)); 50 51 MOCK_METHOD(void, updateSensors, 52 (Sensors & currentSensors, 53 const std::vector<LabeledSensorInfo>& senorParams), 54 (const, override)); 55 56 auto& expectMake( 57 std::optional<TriggerParams> paramsOpt, 58 const testing::Matcher<interfaces::TriggerManager&>& tm, 59 const testing::Matcher<interfaces::JsonStorage&>& triggerStorage) 60 { 61 using namespace testing; 62 63 if (paramsOpt) 64 { 65 const TriggerParams& params = *paramsOpt; 66 67 const auto sensorInfos = 68 utils::fromLabeledSensorsInfo(params.sensors()); 69 70 ON_CALL(*this, getLabeledSensorsInfo(_, sensorInfos)) 71 .WillByDefault(Return(params.sensors())); 72 73 return EXPECT_CALL( 74 *this, make(params.id(), params.name(), 75 utils::transform(params.triggerActions(), 76 [](const auto& action) { 77 return actionToString(action); 78 }), 79 params.reportIds(), tm, triggerStorage, 80 params.thresholdParams(), params.sensors())); 81 } 82 else 83 { 84 const std::vector<LabeledSensorInfo> dummy = { 85 {"service99", 86 "/xyz/openbmc_project/sensors/temperature/BMC_Temp99", 87 "metadata99"}}; 88 89 ON_CALL(*this, getLabeledSensorsInfo(_, _)) 90 .WillByDefault(Return(dummy)); 91 92 return EXPECT_CALL(*this, 93 make(_, _, _, _, tm, triggerStorage, _, dummy)); 94 } 95 } 96 }; 97