#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("");
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();

View File

@ -16,12 +16,12 @@
// under the License.
#include "server/utils.h"
#include "utils/CommonUtil.h"
#include <fstream>
#include <iostream>
#include <thread>
#include <string>
#include <boost/filesystem.hpp>
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);
}

View File

@ -21,8 +21,9 @@
#include <gtest/gtest.h>
#include <chrono>
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: