diff --git a/core/unittest/server/test_config.cpp b/core/unittest/server/test_config.cpp index d408fdee8c8e252f60f2c794d1eddbe823e75a6d..f3adf8a2c3d705c9ebd71dba7f594709cca31e7d 100644 --- a/core/unittest/server/test_config.cpp +++ b/core/unittest/server/test_config.cpp @@ -38,10 +38,11 @@ TEST_F(ConfigTest, CONFIG_TEST) { milvus::Status s = config_mgr->LoadConfigFile(""); 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()); - s = config_mgr->LoadConfigFile(VALID_CONFIG_PATH); + s = config_mgr->LoadConfigFile(config_path + VALID_CONFIG_FILE); ASSERT_TRUE(s.ok()); config_mgr->Print(); @@ -98,8 +99,9 @@ TEST_F(ConfigTest, CONFIG_TEST) { } TEST_F(ConfigTest, SERVER_CONFIG_TEST) { + std::string config_path(CONFIG_PATH); 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()); s = config.ValidateConfig(); diff --git a/core/unittest/server/utils.cpp b/core/unittest/server/utils.cpp index 34c98bea164af27ee65b15753746c8260536c2aa..4c03da6ad917962a534ea2c3b649ea138b35e873 100644 --- a/core/unittest/server/utils.cpp +++ b/core/unittest/server/utils.cpp @@ -16,12 +16,12 @@ // under the License. #include "server/utils.h" +#include "utils/CommonUtil.h" #include #include #include #include -#include namespace { @@ -67,8 +67,8 @@ static const char static const char* INVALID_CONFIG_STR = "*INVALID*"; void -WriteToFile(const char* file_path, const char* content) { - std::fstream fs(file_path, std::ios_base::out); +WriteToFile(const std::string& file_path, const char* content) { + std::fstream fs(file_path.c_str(), std::ios_base::out); //write data to file fs << content; @@ -80,12 +80,14 @@ WriteToFile(const char* file_path, const char* content) { void ConfigTest::SetUp() { - WriteToFile(VALID_CONFIG_PATH, VALID_CONFIG_STR); - WriteToFile(INVALID_CONFIG_PATH, INVALID_CONFIG_STR); + std::string config_path(CONFIG_PATH); + 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 ConfigTest::TearDown() { - boost::filesystem::remove(VALID_CONFIG_PATH); - boost::filesystem::remove(INVALID_CONFIG_PATH); + std::string config_path(CONFIG_PATH); + milvus::server::CommonUtil::DeleteDirectory(config_path); } diff --git a/core/unittest/server/utils.h b/core/unittest/server/utils.h index dc8f0e1a92c44dad4f644add95461a2fa0f62879..2efc5e412034870922e70cc6d7d16bee07450a67 100644 --- a/core/unittest/server/utils.h +++ b/core/unittest/server/utils.h @@ -21,8 +21,9 @@ #include #include -static const char *VALID_CONFIG_PATH = "/tmp/milvus_test/valid_config.yaml"; -static const char *INVALID_CONFIG_PATH = "/tmp/milvus_test/invalid_config.conf"; +static const char *CONFIG_PATH = "/tmp/milvus_test/"; +static const char *VALID_CONFIG_FILE = "valid_config.yaml"; +static const char *INVALID_CONFIG_FILE = "invalid_config.conf"; class ConfigTest : public ::testing::Test { protected: