提交 1aefac8a 编写于 作者: G groot

fix unitest load config error


Former-commit-id: 8bf7417881a421bf5c28a31474743484e8fea155
上级 688a9992
......@@ -132,6 +132,21 @@ bool CommonUtil::IsFileExist(const std::string &path) {
return (access(path.c_str(), F_OK) == 0);
}
std::string CommonUtil::GetExePath() {
const size_t bug_len = 1024;
char exe_path[bug_len];
size_t cnt = readlink("/proc/self/exe", exe_path, bug_len);
if(cnt < 0|| cnt >= bug_len) {
return "";
}
std::string store_path = exe_path;
if(store_path.rfind('/') != store_path.length()){
std::string sub_str = store_path.substr(0, store_path.rfind('/'));
return sub_str + "/";
}
return store_path;
}
}
}
......
......@@ -22,6 +22,8 @@ class CommonUtil {
static bool IsDirectoryExit(const std::string &path);
static ServerError CreateDirectory(const std::string &path);
static ServerError DeleteDirectory(const std::string &path);
static std::string GetExePath();
};
}
......
......@@ -8,13 +8,18 @@
#include <easylogging++.h>
#include "server/ServerConfig.h"
#include "utils/CommonUtil.h"
INITIALIZE_EASYLOGGINGPP
using namespace zilliz::vecwise;
int main(int argc, char **argv) {
std::string config_filename = "../../../conf/server_config.yaml";
std::string exe_path = server::CommonUtil::GetExePath();
std::string config_filename = exe_path + "../../../conf/server_config.yaml";
zilliz::vecwise::server::ServerConfig& config = zilliz::vecwise::server::ServerConfig::GetInstance();
config.LoadConfigFile(config_filename);
std::cout << "Load config file form: " << config_filename << std::endl;
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册