phosphor-ldap-conf: add unit tests
Added uinit tests to create and to restore config file.
Change-Id: Idf5231d46542cda1ff84241aa67aadd91a4788d6
Signed-off-by: Nagaraju Goruganti <ngorugan@in.ibm.com>
Signed-off-by: Deepak Kodihalli <dkodihal@in.ibm.com>
Signed-off-by: Nagaraju Goruganti <ngorugan@in.ibm.com>
diff --git a/phosphor-ldap-config/ldap_configuration.cpp b/phosphor-ldap-config/ldap_configuration.cpp
index 1369362..31e4e75 100644
--- a/phosphor-ldap-config/ldap_configuration.cpp
+++ b/phosphor-ldap-config/ldap_configuration.cpp
@@ -49,10 +49,12 @@
parent.deleteObject();
try
{
- fs::copy_file(defaultNslcdFile, LDAP_CONFIG_FILE,
+ fs::path configDir = fs::path(configFilePath.c_str()).parent_path();
+
+ fs::copy_file(configDir / defaultNslcdFile, LDAP_CONFIG_FILE,
fs::copy_options::overwrite_existing);
- fs::copy_file(linuxNsSwitchFile, nsSwitchFile,
+ fs::copy_file(configDir / linuxNsSwitchFile, configDir / nsSwitchFile,
fs::copy_options::overwrite_existing);
}
catch (const std::exception& e)
@@ -236,6 +238,10 @@
{
throw;
}
+ catch (const InvalidArgument& e)
+ {
+ throw;
+ }
catch (const std::exception& e)
{
log<level::ERR>(e.what());
@@ -270,6 +276,10 @@
{
throw;
}
+ catch (const InvalidArgument& e)
+ {
+ throw;
+ }
catch (const std::exception& e)
{
log<level::ERR>(e.what());
@@ -415,7 +425,8 @@
deleteObject();
try
{
- fs::copy_file(LDAPNsSwitchFile, nsSwitchFile,
+ fs::path configDir = fs::path(configFilePath.c_str()).parent_path();
+ fs::copy_file(configDir / LDAPNsSwitchFile, configDir / nsSwitchFile,
fs::copy_options::overwrite_existing);
}
catch (const std::exception& e)
@@ -442,7 +453,7 @@
if (!fs::exists(filePath))
{
log<level::ERR>("Config file doesn't exists",
- entry("LDAP_CONFIG_FILE=%s", LDAP_CONFIG_FILE));
+ entry("LDAP_CONFIG_FILE=%s", configFilePath.c_str()));
return;
}