From 291a7f597d27b731f8600991ee699b1c06631360 Mon Sep 17 00:00:00 2001 From: John Spray Date: Thu, 13 Jul 2017 08:26:01 -0400 Subject: [PATCH] test: update md_config_t unit test Signed-off-by: John Spray --- src/test/common/test_config.cc | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/test/common/test_config.cc b/src/test/common/test_config.cc index 0af4978ced8..afd24074b73 100644 --- a/src/test/common/test_config.cc +++ b/src/test/common/test_config.cc @@ -27,6 +27,11 @@ extern std::string exec(const char* cmd); // defined in test_hostname.cc class test_md_config_t : public md_config_t, public ::testing::Test { public: + + test_md_config_t() + : md_config_t(true), Test() + {} + void test_expand_meta() { Mutex::Locker l(lock); // successfull meta expansion $run_dir and ${run_dir} @@ -34,6 +39,7 @@ public: ostringstream oss; std::string before = " BEFORE "; std::string after = " AFTER "; + std::string val(before + "$run_dir${run_dir}" + after); EXPECT_TRUE(expand_meta(val, &oss)); EXPECT_EQ(before + "/var/run/ceph/var/run/ceph" + after, val); @@ -112,31 +118,32 @@ public: void test_expand_all_meta() { Mutex::Locker l(lock); int before_count = 0, data_dir = 0; - for (auto& opt: *config_options) { - std::string *str; - opt.conf_ptr(str, this); - if (str) { - if (str->find("$") != string::npos) + for (const auto &i : schema) { + const Option &opt = i.second; + if (opt.type == Option::TYPE_STR) { + const auto &str = boost::get(opt.value); + if (str.find("$") != string::npos) before_count++; - if (str->find("$data_dir") != string::npos) + if (str.find("$data_dir") != string::npos) data_dir++; } } + // if there are no meta variables in the default configuration, // something must be done to check the expected side effect // of expand_all_meta ASSERT_LT(0, before_count); expand_all_meta(); int after_count = 0; - for (auto& opt: *config_options) { - std::string *str; - opt.conf_ptr(str, this); - if (str) { + for (auto& i : values) { + const auto &opt = schema.at(i.first); + if (opt.type == Option::TYPE_STR) { + const std::string &str = boost::get(i.second); size_t pos = 0; - while ((pos = str->find("$", pos)) != string::npos) { - if (str->substr(pos, 8) != "$channel") { + while ((pos = str.find("$", pos)) != string::npos) { + if (str.substr(pos, 8) != "$channel") { std::cout << "unexpected meta-variable found at pos " << pos - << " of '" << *str << "'" << std::endl; + << " of '" << str << "'" << std::endl; after_count++; } pos++; -- 2.39.5