diff options
author | innokentii <innokentii@yandex-team.com> | 2023-05-25 18:03:54 +0300 |
---|---|---|
committer | innokentii <innokentii@yandex-team.com> | 2023-05-25 18:03:54 +0300 |
commit | 86fb23705bc8eeee1c6a68ac18c4e844f2331d19 (patch) | |
tree | 001c9ab123016b95d06af13b5a66245a9d12dbf0 | |
parent | 9e6f7e52150074c7586b0c6b8e6730721c5bdebb (diff) | |
download | ydb-86fb23705bc8eeee1c6a68ac18c4e844f2331d19.tar.gz |
Fix ReplaceMetadata
fix ReplaceMetadata
-rw-r--r-- | ydb/core/cms/console/console_ut_configs.cpp | 4 | ||||
-rw-r--r-- | ydb/core/cms/console/yaml_config/yaml_config.cpp | 12 | ||||
-rw-r--r-- | ydb/core/cms/console/yaml_config/yaml_config_ut.cpp | 70 |
3 files changed, 74 insertions, 12 deletions
diff --git a/ydb/core/cms/console/console_ut_configs.cpp b/ydb/core/cms/console/console_ut_configs.cpp index 534d8ce3f06..c6608adb5eb 100644 --- a/ydb/core/cms/console/console_ut_configs.cpp +++ b/ydb/core/cms/console/console_ut_configs.cpp @@ -672,8 +672,8 @@ selector_config: [] const TString YAML_CONFIG_1_UPDATED = R"( --- metadata: + cluster: "" version: 1 - cluster: )" R"( config: log_config: cluster_name: cluster1 @@ -706,8 +706,8 @@ selector_config: [] const TString YAML_CONFIG_2_UPDATED = R"( --- metadata: + cluster: "" version: 2 - cluster: )" R"( config: log_config: cluster_name: cluster2 diff --git a/ydb/core/cms/console/yaml_config/yaml_config.cpp b/ydb/core/cms/console/yaml_config/yaml_config.cpp index b469f70ca10..529f623c13d 100644 --- a/ydb/core/cms/console/yaml_config/yaml_config.cpp +++ b/ydb/core/cms/console/yaml_config/yaml_config.cpp @@ -734,9 +734,16 @@ TString ReplaceMetadata(const TString& config, const TMetadata& metadata) { TStringStream sstr; auto serializeMetadata = [&]() { - sstr << "metadata:\n version: " << *metadata.Version << "\n cluster: " << *metadata.Cluster; + sstr + << "metadata:\n cluster: \"" + << *metadata.Cluster << "\"" + << "\n version: " + << *metadata.Version; }; if (doc.Root().Style() == NFyaml::ENodeStyle::Flow) { + if (auto pair = doc.Root().Map().pair_at_opt("metadata"); pair) { + doc.Root().Map().Remove(pair); + } serializeMetadata(); sstr << "\n" << doc; } else { @@ -745,6 +752,9 @@ TString ReplaceMetadata(const TString& config, const TMetadata& metadata) { auto end = pair.Value().EndMark().InputPos; sstr << config.substr(0, begin); serializeMetadata(); + if (end < config.length() && config[end] == ':') { + end = end + 1; + } sstr << config.substr(end, TString::npos); } else { if (doc.HasExplicitDocumentStart()) { diff --git a/ydb/core/cms/console/yaml_config/yaml_config_ut.cpp b/ydb/core/cms/console/yaml_config/yaml_config_ut.cpp index 3f389b4f216..6a96f17ac81 100644 --- a/ydb/core/cms/console/yaml_config/yaml_config_ut.cpp +++ b/ydb/core/cms/console/yaml_config/yaml_config_ut.cpp @@ -1529,8 +1529,30 @@ metadata: {} )"; TString exp = R"(metadata: + cluster: "test" + version: 1 +value: 1 +array: +- test: "1" +obj: + value: 2 +)"; + + TString res = NYamlConfig::ReplaceMetadata(str, metadata); + + UNIT_ASSERT_VALUES_EQUAL(res, exp); + } + + { + TString str = R"( +# comment1 +{value: 1, metadata: {version: 1, cluster: "test"}, array: [{test: "1"}], obj: {value: 2}} # comment2 +# comment3 +)"; + + TString exp = R"(metadata: + cluster: "test" version: 1 - cluster: test value: 1 array: - test: "1" @@ -1552,8 +1574,8 @@ obj: {value: 2} # comment2 )"; TString exp = R"(metadata: + cluster: "test" version: 1 - cluster: test # comment1 value: 1 array: [{test: "1"}] @@ -1576,8 +1598,8 @@ obj: {value: 2} # comment2 )"; TString exp = R"(metadata: + cluster: "test" version: 1 - cluster: test # comment1 value: 1 array: [{test: "1"}] @@ -1602,8 +1624,8 @@ obj: {value: 2} # comment2 )"; TString exp = R"(metadata: + cluster: "test" version: 1 - cluster: test # comment1 value: 1 array: [{test: "1"}] @@ -1629,8 +1651,8 @@ obj: {value: 2} # comment2 )"; TString exp = R"(metadata: + cluster: "test" version: 1 - cluster: test # comment1 value: 1 array: [{test: "1"}] @@ -1648,8 +1670,8 @@ obj: {value: 2} # comment2 --- metadata: - version: 0 cluster: tes + version: 0 # comment1 value: 1 array: [{test: "1"}] @@ -1661,8 +1683,8 @@ obj: {value: 2} # comment2 --- metadata: + cluster: "test" version: 1 - cluster: test # comment1 value: 1 array: [{test: "1"}] @@ -1677,7 +1699,6 @@ obj: {value: 2} # comment2 { TString str = R"( - --- # comment1 value: 1 @@ -1687,11 +1708,42 @@ obj: {value: 2} # comment2 )"; TString exp = R"( +--- +metadata: + cluster: "test" + version: 1 +# comment1 +value: 1 +array: [{test: "1"}] +obj: {value: 2} # comment2 +# comment3 +)"; + TString res = NYamlConfig::ReplaceMetadata(str, metadata); + + UNIT_ASSERT_VALUES_EQUAL(res, exp); + } + + metadata.Cluster = ""; + + { + TString str = R"( +--- +metadata: + version: 1 + cluster: +# comment1 +value: 1 +array: [{test: "1"}] +obj: {value: 2} # comment2 +# comment3 +)"; + + TString exp = R"( --- metadata: + cluster: "" version: 1 - cluster: test # comment1 value: 1 array: [{test: "1"}] |