UserManager: Fix unit test cases
User_mgr and ldap_mapper testcases are failing with D-bus errors.
This commit fixes both testcases by using mocked sdbus.
Signed-off-by: Ravi Teja <raviteja28031990@gmail.com>
Change-Id: I3fcabeb1781c938affa11a1370b107d628242374
diff --git a/test/Makefile.am b/test/Makefile.am
index 4f4f9a1..fc6b72e 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -37,7 +37,8 @@
check_PROGRAMS += ldap_mapper_test
ldap_mapper_test_CPPFLAGS = $(cppflags)
ldap_mapper_test_CXXFLAGS = $(cxxflags)
-ldap_mapper_test_LDFLAGS = $(ldflags)
+ldap_mapper_test_LDFLAGS = $(ldflags) \
+ -lgmock
ldap_mapper_test_SOURCES = ldap_mapper_test.cpp
ldap_mapper_test_LDADD = $(top_builddir)/phosphor-ldap-mapper/ldap_mapper_entry.o \
$(top_builddir)/phosphor-ldap-mapper/ldap_mapper_mgr.o \
diff --git a/test/ldap_mapper_test.cpp b/test/ldap_mapper_test.cpp
index 9853c85..b3c1a4f 100644
--- a/test/ldap_mapper_test.cpp
+++ b/test/ldap_mapper_test.cpp
@@ -8,6 +8,7 @@
#include <xyz/openbmc_project/Common/error.hpp>
#include <xyz/openbmc_project/User/Common/error.hpp>
#include "config.h"
+#include <sdbusplus/test/sdbus_mock.hpp>
namespace phosphor
{
@@ -19,7 +20,9 @@
class TestSerialization : public testing::Test
{
public:
- TestSerialization() : bus(sdbusplus::bus::new_default())
+ sdbusplus::SdBusMock sdbusMock;
+
+ TestSerialization() : bus(sdbusplus::get_mocked_new(&sdbusMock))
{
}
diff --git a/test/user_mgr_test.cpp b/test/user_mgr_test.cpp
index 83ae651..88911cd 100644
--- a/test/user_mgr_test.cpp
+++ b/test/user_mgr_test.cpp
@@ -3,6 +3,7 @@
#include <xyz/openbmc_project/Common/error.hpp>
#include <gtest/gtest.h>
#include <exception>
+#include <sdbusplus/test/sdbus_mock.hpp>
namespace phosphor
{
@@ -17,11 +18,12 @@
class TestUserMgr : public testing::Test
{
public:
+ sdbusplus::SdBusMock sdbusMock;
sdbusplus::bus::bus bus;
MockManager mockManager;
TestUserMgr() :
- bus(sdbusplus::bus::new_default()), mockManager(bus, objpath)
+ bus(sdbusplus::get_mocked_new(&sdbusMock)), mockManager(bus, objpath)
{
}