From 4607220a30b15ba3f891f88393ebd63b112d07e0 Mon Sep 17 00:00:00 2001 From: Stepan Blyschak Date: Fri, 17 May 2024 09:30:09 +0300 Subject: [PATCH] Get back mock as it is used by other tests Signed-off-by: Stepan Blyschak --- tests/mock_tests/Makefile.am | 2 +- tests/mock_tests/fake_response_publisher.cpp | 21 ++++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/tests/mock_tests/Makefile.am b/tests/mock_tests/Makefile.am index 7bafd29e3e..24b0d513ec 100644 --- a/tests/mock_tests/Makefile.am +++ b/tests/mock_tests/Makefile.am @@ -201,7 +201,7 @@ tests_intfmgrd_INCLUDES = $(tests_INCLUDES) -I$(top_srcdir)/cfgmgr -I$(top_srcdi tests_intfmgrd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_GTEST) $(CFLAGS_SAI) tests_intfmgrd_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_GTEST) $(CFLAGS_SAI) $(tests_intfmgrd_INCLUDES) tests_intfmgrd_LDADD = $(LDADD_GTEST) $(LDADD_SAI) -lnl-genl-3 -lhiredis -lhiredis \ - -lswsscommon -lswsscommon -lgtest -lgtest_main -lzmq -lnl-3 -lnl-route-3 -lpthread + -lswsscommon -lswsscommon -lgtest -lgtest_main -lzmq -lnl-3 -lnl-route-3 -lpthread -lgmock -lgmock_main ## teammgrd unit tests diff --git a/tests/mock_tests/fake_response_publisher.cpp b/tests/mock_tests/fake_response_publisher.cpp index c2cbc9fcd6..5e6aa0f2a0 100644 --- a/tests/mock_tests/fake_response_publisher.cpp +++ b/tests/mock_tests/fake_response_publisher.cpp @@ -2,6 +2,11 @@ #include #include "response_publisher.h" +#include "mock_response_publisher.h" + +/* This mock plugs into this fake response publisher implementation + * when needed to test code that uses response publisher. */ +std::unique_ptr gMockResponsePublisher; ResponsePublisher::ResponsePublisher(const std::string& dbName, bool buffered, bool db_write_thread) : m_db(std::make_unique(dbName, 0)), m_buffered(buffered) {} @@ -12,12 +17,24 @@ void ResponsePublisher::publish( const std::string& table, const std::string& key, const std::vector& intent_attrs, const ReturnCode& status, - const std::vector& state_attrs, bool replace) {} + const std::vector& state_attrs, bool replace) +{ + if (gMockResponsePublisher) + { + gMockResponsePublisher->publish(table, key, intent_attrs, status, state_attrs, replace); + } +} void ResponsePublisher::publish( const std::string& table, const std::string& key, const std::vector& intent_attrs, - const ReturnCode& status, bool replace) {} + const ReturnCode& status, bool replace) +{ + if (gMockResponsePublisher) + { + gMockResponsePublisher->publish(table, key, intent_attrs, status, replace); + } +} void ResponsePublisher::writeToDB( const std::string& table, const std::string& key,