-
Notifications
You must be signed in to change notification settings - Fork 411
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix invalid storage dir configurations lead to unexpected behavior (#…
- Loading branch information
1 parent
abfb038
commit 15c97cb
Showing
4 changed files
with
435 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
#include <TestUtils/TiFlashTestBasic.h> | ||
#include <common/logger_useful.h> | ||
#include <cpptoml.h> | ||
|
||
#include <sstream> | ||
|
||
namespace DB::tests | ||
{ | ||
TEST(CPPTomlTest, ContainsQualifiedArray) | ||
{ | ||
auto * log = &Poco::Logger::get("CPPTomlTest"); | ||
|
||
Strings failure_tests = { | ||
R"( | ||
[a] | ||
[a.b] | ||
c = "abc" | ||
)", | ||
R"( | ||
[a] | ||
[a.b] | ||
c = 123 | ||
)", | ||
R"( | ||
[a] | ||
[a.b] | ||
c = 123.45 | ||
)", | ||
}; | ||
|
||
for (size_t i = 0; i < failure_tests.size(); ++i) | ||
{ | ||
const auto & test_case = failure_tests[i]; | ||
SCOPED_TRACE(fmt::format("[index={}] [content={}]", i, test_case)); | ||
LOG_FMT_INFO(log, "parsing [index={}] [content={}]", i, test_case); | ||
|
||
std::istringstream ss(test_case); | ||
cpptoml::parser p(ss); | ||
auto table = p.parse(); | ||
|
||
const char * key = "a.b.c"; | ||
ASSERT_TRUE(table->contains_qualified(key)); | ||
auto qualified = table->get_qualified(key); | ||
ASSERT_TRUE(qualified); | ||
// not array | ||
ASSERT_FALSE(qualified->is_array()); | ||
// try to parse as vector<string>, return false | ||
cpptoml::option<Strings> array = table->get_qualified_array_of<String>(key); | ||
ASSERT_FALSE(array); | ||
} | ||
} | ||
|
||
TEST(CPPTomlTest, ContainsQualifiedStringArray) | ||
{ | ||
auto * log = &Poco::Logger::get("CPPTomlTest"); | ||
|
||
Strings failure_tests = { | ||
R"( | ||
[a] | ||
[a.b] | ||
c = [["abc", "def"], ["z"]] | ||
)", | ||
R"( | ||
[a] | ||
[a.b] | ||
c = [123, 456] | ||
)", | ||
}; | ||
|
||
for (size_t i = 0; i < failure_tests.size(); ++i) | ||
{ | ||
const auto & test_case = failure_tests[i]; | ||
SCOPED_TRACE(fmt::format("[index={}] [content={}]", i, test_case)); | ||
LOG_FMT_INFO(log, "parsing [index={}] [content={}]", i, test_case); | ||
|
||
std::istringstream ss(test_case); | ||
cpptoml::parser p(ss); | ||
auto table = p.parse(); | ||
|
||
const char * key = "a.b.c"; | ||
ASSERT_TRUE(table->contains_qualified(key)); | ||
auto qualified = table->get_qualified(key); | ||
ASSERT_TRUE(qualified); | ||
// is non-empty array but not string array | ||
ASSERT_TRUE(qualified->is_array()); | ||
auto qualified_array = qualified->as_array(); | ||
ASSERT_NE(qualified_array->begin(), qualified_array->end()); | ||
// try to parse as vector<string>, return false | ||
cpptoml::option<Strings> array = table->get_qualified_array_of<String>(key); | ||
ASSERT_FALSE(array); | ||
} | ||
} | ||
|
||
TEST(CPPTomlTest, ContainsQualifiedStringArrayOrEmpty) | ||
{ | ||
auto * log = &Poco::Logger::get("CPPTomlTest"); | ||
|
||
Strings failure_tests = { | ||
// a.b.c is not empty | ||
R"( | ||
[a] | ||
[a.b] | ||
c = ["abc", "def", "z"] | ||
)", | ||
// a.b.c is empty | ||
R"( | ||
[a] | ||
[a.b] | ||
c = [] | ||
)", | ||
}; | ||
|
||
for (size_t i = 0; i < failure_tests.size(); ++i) | ||
{ | ||
const auto & test_case = failure_tests[i]; | ||
SCOPED_TRACE(fmt::format("[index={}] [content={}]", i, test_case)); | ||
LOG_FMT_INFO(log, "parsing [index={}] [content={}]", i, test_case); | ||
|
||
std::istringstream ss(test_case); | ||
cpptoml::parser p(ss); | ||
auto table = p.parse(); | ||
|
||
const char * key = "a.b.c"; | ||
ASSERT_TRUE(table->contains_qualified(key)); | ||
auto qualified = table->get_qualified(key); | ||
ASSERT_TRUE(qualified); | ||
// is non-empty array but not string array | ||
ASSERT_TRUE(qualified->is_array()); | ||
|
||
// try to parse as vector<string>, return true | ||
cpptoml::option<Strings> array = table->get_qualified_array_of<String>(key); | ||
ASSERT_TRUE(array); | ||
if (auto qualified_array = qualified->as_array(); qualified_array->begin() != qualified_array->end()) | ||
{ | ||
ASSERT_EQ(array->size(), 3); | ||
} | ||
} | ||
} | ||
|
||
} // namespace DB::tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.