add test cases

This commit is contained in:
sakulali 2024-07-31 21:33:14 +08:00
parent 7d36cfeeaf
commit bca21bc6c7
3 changed files with 25 additions and 7 deletions

View File

@ -654,21 +654,18 @@ XMLDocumentPtr ConfigProcessor::parseConfig(const std::string & config_path)
while (std::getline(file, line)) while (std::getline(file, line))
{ {
const size_t pos = firstNonWhitespacePos(line); const size_t pos = firstNonWhitespacePos(line);
if (pos == std::string::npos)
continue;
if (pos < line.size() && '<' == line[pos]) if (pos < line.size() && '<' == line[pos])
{ {
maybe_xml = true; maybe_xml = true;
break;
} }
else if (pos != std::string::npos)
break; break;
} }
} }
if (maybe_xml) if (maybe_xml)
return dom_parser.parse(config_path); return dom_parser.parse(config_path);
else
return YAMLParser::parse(config_path); return YAMLParser::parse(config_path);
} }
} }

View File

@ -18,3 +18,7 @@ autodetect xml (non leading whitespaces)
2 2
autodetect yaml autodetect yaml
2 2
autodetect invalid xml
Code: 1000, e.code() = 0, SAXParseException: Invalid token in '/config_test.badxml', line 2 column 12, Stack trace (when copying this message, always include the lines below):
autodetect invalid yaml
Code: 585. Unable to parse YAML configuration file /config_test.badyaml, yaml-cpp: error at line 2, column 12: illegal map value. (CANNOT_PARSE_YAML)

View File

@ -15,6 +15,8 @@ yaml_config=$CLICKHOUSE_TMP/config_$CLICKHOUSE_DATABASE.yaml
autodetect_xml_with_leading_whitespace_config=$CLICKHOUSE_TMP/config_$CLICKHOUSE_DATABASE.config autodetect_xml_with_leading_whitespace_config=$CLICKHOUSE_TMP/config_$CLICKHOUSE_DATABASE.config
autodetect_xml_non_leading_whitespace_config=$CLICKHOUSE_TMP/config_$CLICKHOUSE_DATABASE.cfg autodetect_xml_non_leading_whitespace_config=$CLICKHOUSE_TMP/config_$CLICKHOUSE_DATABASE.cfg
autodetect_yaml_config=$CLICKHOUSE_TMP/config_$CLICKHOUSE_DATABASE.properties autodetect_yaml_config=$CLICKHOUSE_TMP/config_$CLICKHOUSE_DATABASE.properties
autodetect_invalid_xml_config=$CLICKHOUSE_TMP/config_$CLICKHOUSE_DATABASE.badxml
autodetect_invalid_yaml_config=$CLICKHOUSE_TMP/config_$CLICKHOUSE_DATABASE.badyaml
function cleanup() function cleanup()
{ {
@ -27,6 +29,8 @@ function cleanup()
rm "${autodetect_xml_with_leading_whitespace_config:?}" rm "${autodetect_xml_with_leading_whitespace_config:?}"
rm "${autodetect_xml_non_leading_whitespace_config:?}" rm "${autodetect_xml_non_leading_whitespace_config:?}"
rm "${autodetect_yaml_config:?}" rm "${autodetect_yaml_config:?}"
rm "${autodetect_invalid_xml_config:?}"
rm "${autodetect_invalid_yaml_config:?}"
} }
trap cleanup EXIT trap cleanup EXIT
@ -70,6 +74,15 @@ EOL
cat > "$autodetect_yaml_config" <<EOL cat > "$autodetect_yaml_config" <<EOL
max_threads: 2 max_threads: 2
EOL EOL
cat > "$autodetect_invalid_xml_config" <<EOL
<!-- This is a XML file comment -->
<invalid tag><invalid tag>
EOL
cat > "$autodetect_invalid_yaml_config" <<EOL
; This is a INI file comment
max_threads: 2
EOL
echo 'default' echo 'default'
$CLICKHOUSE_CLIENT --config "$config" -q "select getSetting('max_threads')" $CLICKHOUSE_CLIENT --config "$config" -q "select getSetting('max_threads')"
@ -95,3 +108,7 @@ echo 'autodetect xml (non leading whitespaces)'
$CLICKHOUSE_CLIENT --config "$autodetect_xml_non_leading_whitespace_config" -q "select getSetting('max_threads')" $CLICKHOUSE_CLIENT --config "$autodetect_xml_non_leading_whitespace_config" -q "select getSetting('max_threads')"
echo 'autodetect yaml' echo 'autodetect yaml'
$CLICKHOUSE_CLIENT --config "$autodetect_yaml_config" -q "select getSetting('max_threads')" $CLICKHOUSE_CLIENT --config "$autodetect_yaml_config" -q "select getSetting('max_threads')"
echo 'autodetect invalid xml'
$CLICKHOUSE_CLIENT --config "$autodetect_invalid_xml_config" -q "select getSetting('max_threads')" 2>&1 |& sed -n '1p' | sed -e "s#$CLICKHOUSE_TMP##" -e "s#Poco::Exception. ##"
echo 'autodetect invalid yaml'
$CLICKHOUSE_CLIENT --config "$autodetect_invalid_yaml_config" -q "select getSetting('max_threads')" 2>&1 |& sed -n '1p' | sed -e "s#$CLICKHOUSE_TMP##" -e "s#DB::Exception: ##"