#48 Config unittest failed

Former-commit-id: e07a067382ed00efc9c5d914b4100592bb7aee44
This commit is contained in:
starlord 2019-10-19 19:31:22 +08:00
parent 73d2f7c765
commit 6e11f4e4e7
3 changed files with 17 additions and 12 deletions

View File

@ -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) {
} }
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();

View File

@ -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
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) {
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);
} }

View File

@ -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: