Skip to content

Commit

Permalink
Add SwitchConfigContainer tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kcudnik committed Aug 23, 2021
1 parent 7a32cd6 commit 1b4d6d1
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
3 changes: 2 additions & 1 deletion unittest/vslib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ tests_SOURCES = main.cpp \
TestResourceLimiterParser.cpp \
TestSaiUnittests.cpp \
TestSelectableFd.cpp \
TestSignal.cpp
TestSignal.cpp \
TestSwitchConfigContainer.cpp

tests_CXXFLAGS = $(DBGFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS_COMMON)
tests_LDADD = $(LDADD_GTEST) $(top_srcdir)/vslib/libSaiVS.a -lhiredis -lswsscommon -lnl-genl-3 -lnl-nf-3 -lnl-route-3 -lnl-3 \
Expand Down
37 changes: 37 additions & 0 deletions unittest/vslib/TestSwitchConfigContainer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include "SwitchConfigContainer.h"

#include <gtest/gtest.h>

using namespace saivs;

TEST(SwitchConfigContainer, insert)
{
SwitchConfigContainer scc;

EXPECT_THROW(scc.insert(nullptr), std::runtime_error);

auto sc0 = std::make_shared<SwitchConfig>(0,"foo");
auto sc1 = std::make_shared<SwitchConfig>(0,"bar");
auto sc2 = std::make_shared<SwitchConfig>(1,"bar");

scc.insert(sc1);

EXPECT_THROW(scc.insert(sc0), std::runtime_error);

EXPECT_THROW(scc.insert(sc2), std::runtime_error);
}

TEST(SwitchConfigContainer, getConfig)
{
SwitchConfigContainer scc;

auto sc0 = std::make_shared<SwitchConfig>(0,"foo");
auto sc1 = std::make_shared<SwitchConfig>(1,"bar");

scc.insert(sc0);
scc.insert(sc1);

EXPECT_EQ(scc.getConfig(2), nullptr);
EXPECT_NE(scc.getConfig(0), nullptr);
EXPECT_NE(scc.getConfig(1), nullptr);
}
5 changes: 5 additions & 0 deletions vslib/SwitchConfigContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ void SwitchConfigContainer::insert(
{
SWSS_LOG_ENTER();

if (config == nullptr)
{
SWSS_LOG_THROW("switch config pointer can't be nullptr");
}

auto it = m_indexToConfig.find(config->m_switchIndex);

if (it != m_indexToConfig.end())
Expand Down

0 comments on commit 1b4d6d1

Please sign in to comment.