xref: /openbmc/telemetry/tests/src/mocks/trigger_factory_mock.hpp (revision 405c1e4bf8b993cb3800adead546e91b030ecb9b)
1 #pragma once
2 
3 #include "interfaces/trigger_factory.hpp"
4 #include "mocks/trigger_mock.hpp"
5 #include "params/trigger_params.hpp"
6 
7 #include <gmock/gmock.h>
8 
9 class TriggerFactoryMock : public interfaces::TriggerFactory
10 {
11   public:
12     TriggerFactoryMock()
13     {
14         using namespace testing;
15 
16         ON_CALL(*this, make(_, _, _, _, _, _, _, _, _, _))
17             .WillByDefault(WithArgs<1>(Invoke([](const std::string& name) {
18                 return std::make_unique<NiceMock<TriggerMock>>(name);
19             })));
20     }
21 
22     MOCK_METHOD(
23         std::unique_ptr<interfaces::Trigger>, make,
24         (boost::asio::yield_context&, const std::string& name, bool isDiscrete,
25          bool logToJournal, bool logToRedfish, bool updateReport,
26          (const std::vector<
27              std::pair<sdbusplus::message::object_path, std::string>>& sensors),
28          const std::vector<std::string>& reportNames,
29          const TriggerThresholdParams& thresholdParams,
30          interfaces::TriggerManager& triggerManager),
31         (const, override));
32 
33     auto& expectMake(
34         std::optional<std::reference_wrapper<const TriggerParams>> paramsOpt,
35         const testing::Matcher<interfaces::TriggerManager&>& tm)
36     {
37         using namespace testing;
38 
39         if (paramsOpt)
40         {
41             const TriggerParams& params = *paramsOpt;
42             return EXPECT_CALL(
43                 *this,
44                 make(_, params.name(), params.isDiscrete(),
45                      params.logToJournal(), params.logToRedfish(),
46                      params.updateReport(), params.sensors(),
47                      params.reportNames(), params.thresholdParams(), tm));
48         }
49         else
50         {
51             return EXPECT_CALL(*this, make(_, _, _, _, _, _, _, _, _, tm));
52         }
53     }
54 };
55