Skip to content

Commit

Permalink
Add vslib ContextConfigContainer tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kcudnik committed Aug 23, 2021
1 parent bc27a04 commit d6f7435
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 2 deletions.
1 change: 0 additions & 1 deletion unittest/lib/test_sai_redis_interfacequery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ TEST(libsairedis, sai_switch_id_query)
EXPECT_EQ(SAI_NULL_OBJECT_ID, sai_switch_id_query(SAI_NULL_OBJECT_ID));
}


TEST(libsairedis, sai_bulk_get_attribute)
{
EXPECT_EQ(SAI_STATUS_NOT_IMPLEMENTED, sai_bulk_get_attribute(0,SAI_OBJECT_TYPE_NULL,0,0,0,0,0));
Expand Down
3 changes: 2 additions & 1 deletion unittest/vslib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ bin_PROGRAMS = tests testslibsaivs
LDADD_GTEST = -L/usr/src/gtest -lgtest -lgtest_main

tests_SOURCES = main.cpp \
TestBuffer.cpp
TestBuffer.cpp \
TestContextConfigContainer.cpp

tests_CXXFLAGS = $(DBGFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS_COMMON)
tests_LDADD = $(LDADD_GTEST) $(top_srcdir)/vslib/libSaiVS.a -lhiredis -lswsscommon -lpthread -L$(top_srcdir)/meta/.libs -lsaimetadata -lsaimeta -lzmq $(CODE_COVERAGE_LIBS)
Expand Down
44 changes: 44 additions & 0 deletions unittest/vslib/TestContextConfigContainer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include "ContextConfigContainer.h"

#include <gtest/gtest.h>

using namespace saivs;

TEST(ContextConfigContainer, insert)
{
auto cc = std::make_shared<ContextConfig>(1, "foo");

ContextConfigContainer ccc;

ccc.insert(cc);

EXPECT_EQ(ccc.get(2), nullptr);
EXPECT_NE(ccc.get(1), nullptr);
}

TEST(ContextConfigContainer, loadFromFile)
{
// on non existing file, default should be loaded

auto ccc = ContextConfigContainer::loadFromFile("foo");

EXPECT_NE(ccc, nullptr);
EXPECT_NE(ccc->get(0), nullptr);
EXPECT_EQ(ccc->get(0)->m_guid, 0);
EXPECT_EQ(ccc->get(0)->m_name, "VirtualSwitch");

ccc = ContextConfigContainer::loadFromFile("files/context_config.bad.json");

EXPECT_NE(ccc, nullptr);
EXPECT_NE(ccc->get(0), nullptr);
EXPECT_EQ(ccc->get(0)->m_guid, 0);
EXPECT_EQ(ccc->get(0)->m_name, "VirtualSwitch");

ccc = ContextConfigContainer::loadFromFile("files/context_config.good.json");

EXPECT_NE(ccc, nullptr);
EXPECT_NE(ccc->get(0), nullptr);
EXPECT_EQ(ccc->get(0)->m_guid, 0);
EXPECT_EQ(ccc->get(0)->m_name, "syncd");

}
1 change: 1 addition & 0 deletions unittest/vslib/files/context_config.bad.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foo
25 changes: 25 additions & 0 deletions unittest/vslib/files/context_config.good.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"CONTEXTS": [
{
"guid" : 0,
"name" : "syncd",
"dbAsic" : "ASIC_DB",
"dbCounters" : "COUNTERS_DB",
"dbFlex": "FLEX_COUNTER_DB",
"dbState" : "STATE_DB",
"zmq_enable": false,
"zmq_endpoint": "tcp://127.0.0.1:5555",
"zmq_ntf_endpoint": "tcp://127.0.0.1:5556",
"switches": [
{
"index" : 0,
"hwinfo" : ""
},
{
"index" : 1,
"hwinfo" : "1"
}
]
}
]
}

0 comments on commit d6f7435

Please sign in to comment.