Skip to content

Commit

Permalink
add UT for response publisher
Browse files Browse the repository at this point in the history
Signed-off-by: Stepan Blyschak <stepanb@nvidia.com>
  • Loading branch information
stepanblyschak committed Feb 6, 2023
1 parent dfd360d commit 235bbde
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ swssconfig/swssplayer
tlm_teamd/tlm_teamd
teamsyncd/teamsyncd
tests/tests
tests/mock_tests/tests_response_publisher


# Test Files #
Expand Down
18 changes: 16 additions & 2 deletions tests/mock_tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ P4_ORCH_DIR = $(top_srcdir)/orchagent/p4orch

CFLAGS_SAI = -I /usr/include/sai

TESTS = tests tests_intfmgrd tests_portsyncd
TESTS = tests tests_intfmgrd tests_portsyncd tests_response_publisher

noinst_PROGRAMS = tests tests_intfmgrd tests_portsyncd
noinst_PROGRAMS = tests tests_intfmgrd tests_portsyncd tests_response_publisher

LDADD_SAI = -lsaimeta -lsaimetadata -lsaivs -lsairedis

Expand Down Expand Up @@ -166,3 +166,17 @@ tests_intfmgrd_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_GTEST
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

tests_response_publisher_SOURCES = response_publisher/response_publisher_ut.cpp \
$(top_srcdir)/orchagent/response_publisher.cpp \
mock_orchagent_main.cpp \
mock_dbconnector.cpp \
mock_table.cpp \
mock_hiredis.cpp \
mock_redisreply.cpp

tests_response_publisher_INCLUDES = $(tests_INCLUDES)
tests_response_publisher_CFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_GTEST) $(CFLAGS_SAI)
tests_response_publisher_CPPFLAGS = $(DBGFLAGS) $(AM_CFLAGS) $(CFLAGS_COMMON) $(CFLAGS_GTEST) $(CFLAGS_SAI) $(tests_response_publisher_INCLUDES)
tests_response_publisher_LDADD = $(LDADD_GTEST) $(LDADD_SAI) -lnl-genl-3 -lhiredis -lhiredis \
-lswsscommon -lswsscommon -lgtest -lgtest_main -lzmq -lnl-3 -lnl-route-3 -lpthread
37 changes: 37 additions & 0 deletions tests/mock_tests/response_publisher/response_publisher_ut.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include "response_publisher.h"

#include <gtest/gtest.h>

bool gResponsePublisherRecord{false};
bool gResponsePublisherLogRotate{false};
std::ofstream gResponsePublisherRecordOfs;
std::string gResponsePublisherRecordFile;

using namespace swss;

TEST(ResponsePublisher, TestPublish)
{
DBConnector conn{"APPL_STATE_DB", 0};
Table stateTable{&conn, "SOME_TABLE"};
std::string value;
ResponsePublisher publisher{};

publisher.publish("SOME_TABLE", "SOME_KEY", {{"field", "value"}}, ReturnCode(SAI_STATUS_SUCCESS));
ASSERT_TRUE(stateTable.hget("SOME_KEY", "field", value));
ASSERT_EQ(value, "value");
}

TEST(ResponsePublisher, TestPublishBuffered)
{
DBConnector conn{"APPL_STATE_DB", 0};
Table stateTable{&conn, "SOME_TABLE"};
std::string value;
ResponsePublisher publisher{};

publisher.setBuffered(true);

publisher.publish("SOME_TABLE", "SOME_KEY", {{"field", "value"}}, ReturnCode(SAI_STATUS_SUCCESS));
publisher.flush();
ASSERT_TRUE(stateTable.hget("SOME_KEY", "field", value));
ASSERT_EQ(value, "value");
}

0 comments on commit 235bbde

Please sign in to comment.