提交 5f05f8b3 编写于 作者: G groot

#48 Config unittest failed


Former-commit-id: 528fa91b59745822d81e3e9ee7cd23fff2382292
上级 49e05252
...@@ -38,10 +38,11 @@ TEST_F(ConfigTest, CONFIG_TEST) { ...@@ -38,10 +38,11 @@ TEST_F(ConfigTest, CONFIG_TEST) {
milvus::Status s = config_mgr->LoadConfigFile(""); milvus::Status s = config_mgr->LoadConfigFile("");
ASSERT_FALSE(s.ok()); ASSERT_FALSE(s.ok());
s = config_mgr->LoadConfigFile(INVALID_CONFIG_PATH); std::string config_path(CONFIG_PATH);
s = config_mgr->LoadConfigFile(config_path+ INVALID_CONFIG_FILE);
ASSERT_FALSE(s.ok()); ASSERT_FALSE(s.ok());
s = config_mgr->LoadConfigFile(VALID_CONFIG_PATH); s = config_mgr->LoadConfigFile(config_path + VALID_CONFIG_FILE);
ASSERT_TRUE(s.ok()); ASSERT_TRUE(s.ok());
config_mgr->Print(); config_mgr->Print();
...@@ -98,8 +99,9 @@ TEST_F(ConfigTest, CONFIG_TEST) { ...@@ -98,8 +99,9 @@ TEST_F(ConfigTest, CONFIG_TEST) {
} }
TEST_F(ConfigTest, SERVER_CONFIG_TEST) { TEST_F(ConfigTest, SERVER_CONFIG_TEST) {
std::string config_path(CONFIG_PATH);
milvus::server::Config &config = milvus::server::Config::GetInstance(); milvus::server::Config &config = milvus::server::Config::GetInstance();
milvus::Status s = config.LoadConfigFile(VALID_CONFIG_PATH); milvus::Status s = config.LoadConfigFile(config_path + VALID_CONFIG_FILE);
ASSERT_TRUE(s.ok()); ASSERT_TRUE(s.ok());
s = config.ValidateConfig(); s = config.ValidateConfig();
......
...@@ -16,12 +16,12 @@ ...@@ -16,12 +16,12 @@
// under the License. // under the License.
#include "server/utils.h" #include "server/utils.h"
#include "utils/CommonUtil.h"
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include <thread> #include <thread>
#include <string> #include <string>
#include <boost/filesystem.hpp>
namespace { namespace {
...@@ -67,8 +67,8 @@ static const char ...@@ -67,8 +67,8 @@ static const char
static const char* INVALID_CONFIG_STR = "*INVALID*"; static const char* INVALID_CONFIG_STR = "*INVALID*";
void void
WriteToFile(const char* file_path, const char* content) { WriteToFile(const std::string& file_path, const char* content) {
std::fstream fs(file_path, std::ios_base::out); std::fstream fs(file_path.c_str(), std::ios_base::out);
//write data to file //write data to file
fs << content; fs << content;
...@@ -80,12 +80,14 @@ WriteToFile(const char* file_path, const char* content) { ...@@ -80,12 +80,14 @@ WriteToFile(const char* file_path, const char* content) {
void void
ConfigTest::SetUp() { ConfigTest::SetUp() {
WriteToFile(VALID_CONFIG_PATH, VALID_CONFIG_STR); std::string config_path(CONFIG_PATH);
WriteToFile(INVALID_CONFIG_PATH, INVALID_CONFIG_STR); milvus::server::CommonUtil::CreateDirectory(config_path);
WriteToFile(config_path + VALID_CONFIG_FILE, VALID_CONFIG_STR);
WriteToFile(config_path+ INVALID_CONFIG_FILE, INVALID_CONFIG_STR);
} }
void void
ConfigTest::TearDown() { ConfigTest::TearDown() {
boost::filesystem::remove(VALID_CONFIG_PATH); std::string config_path(CONFIG_PATH);
boost::filesystem::remove(INVALID_CONFIG_PATH); milvus::server::CommonUtil::DeleteDirectory(config_path);
} }
...@@ -21,8 +21,9 @@ ...@@ -21,8 +21,9 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <chrono> #include <chrono>
static const char *VALID_CONFIG_PATH = "/tmp/milvus_test/valid_config.yaml"; static const char *CONFIG_PATH = "/tmp/milvus_test/";
static const char *INVALID_CONFIG_PATH = "/tmp/milvus_test/invalid_config.conf"; static const char *VALID_CONFIG_FILE = "valid_config.yaml";
static const char *INVALID_CONFIG_FILE = "invalid_config.conf";
class ConfigTest : public ::testing::Test { class ConfigTest : public ::testing::Test {
protected: protected:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册