diff options
author | Sara Golemon <sara.golemon@mongodb.com> | 2018-12-12 22:29:39 +0000 |
---|---|---|
committer | Sara Golemon <sara.golemon@mongodb.com> | 2018-12-14 17:07:05 +0000 |
commit | 177c1d3d5f9e4f67ef17ef9506aaf0e0c5a14703 (patch) | |
tree | 44c1648e27b5ccaca4a74c10ad6df2e59708bd3b /src | |
parent | 9368a529cb1f8d278866ea017d51df54b3650578 (diff) | |
download | mongo-177c1d3d5f9e4f67ef17ef9506aaf0e0c5a14703.tar.gz |
SERVER-38572 Allow arbitrary C++ expressions in literal values
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/idl/config_option_test.cpp | 22 | ||||
-rw-r--r-- | src/mongo/idl/config_option_test.h | 5 | ||||
-rw-r--r-- | src/mongo/idl/config_option_test.idl | 20 | ||||
-rw-r--r-- | src/mongo/idl/server_parameter_with_storage_test.cpp | 14 | ||||
-rw-r--r-- | src/mongo/idl/server_parameter_with_storage_test.h | 4 | ||||
-rw-r--r-- | src/mongo/idl/server_parameter_with_storage_test.idl | 14 |
6 files changed, 73 insertions, 6 deletions
diff --git a/src/mongo/idl/config_option_test.cpp b/src/mongo/idl/config_option_test.cpp index 6b4c1f1fa7f..640bf1b6ef3 100644 --- a/src/mongo/idl/config_option_test.cpp +++ b/src/mongo/idl/config_option_test.cpp @@ -592,6 +592,28 @@ TEST(RedactionBSON, SubObjects) { ASSERT_BSONOBJ_EQ(res, obj); } +TEST(ConfigOption, Opt17) { + ASSERT_OPTION_SET<std::int32_t>( + moe::startupOptionsParsed, "test.config.opt17", kTestConfigOpt17Default); + + moe::Environment implicitParse; + ASSERT_OK(parseArgv({"mongod", "--testConfigOpt17"}, &implicitParse)); + ASSERT_OPTION_SET<std::int32_t>(implicitParse, "test.config.opt17", kTestConfigOpt17Implicit); + + moe::Environment negativeParse; + ASSERT_NOT_OK( + parseArgv({"mongod", "--testConfigOpt17", std::to_string(kTestConfigOpt17Minimum - 1)}, + &negativeParse)); + ASSERT_NOT_OK( + parseArgv({"mongod", "--testConfigOpt17", std::to_string(kTestConfigOpt17Maximum + 1)}, + &negativeParse)); + + moe::Environment okParse; + ASSERT_OK(parseArgv({"mongod", "--testConfigOpt17", std::to_string(kTestConfigOpt17Minimum)}, + &okParse)); + ASSERT_OPTION_SET<std::int32_t>(okParse, "test.config.opt17", kTestConfigOpt17Minimum); +} + } // namespace } // namespace test } // namespace mongo diff --git a/src/mongo/idl/config_option_test.h b/src/mongo/idl/config_option_test.h index e0de0b68c03..faf6390c96e 100644 --- a/src/mongo/idl/config_option_test.h +++ b/src/mongo/idl/config_option_test.h @@ -35,5 +35,10 @@ namespace test { extern bool gEnableTestConfigOpt14; extern bool gEnableTestConfigOpt15; +constexpr std::int32_t kTestConfigOpt17Default = 42; +constexpr std::int32_t kTestConfigOpt17Implicit = 43; +constexpr std::int32_t kTestConfigOpt17Minimum = 5; +constexpr std::int32_t kTestConfigOpt17Maximum = 100; + } // namespace test } // namespace mongo diff --git a/src/mongo/idl/config_option_test.idl b/src/mongo/idl/config_option_test.idl index a36d7d26e46..d5eaf220195 100644 --- a/src/mongo/idl/config_option_test.idl +++ b/src/mongo/idl/config_option_test.idl @@ -34,9 +34,6 @@ global: configs: initializer_name: TestConfigs -imports: - - "mongo/idl/basic_types.idl" - configs: "test.config.opt1": short_name: testConfigOpt1 @@ -188,3 +185,20 @@ configs: source: cli redact: true + "test.config.opt17": + description: "Test c++ expressions in default, implicit, validator" + short_name: testConfigOpt17 + arg_vartype: Int + source: cli + default: + expr: kTestConfigOpt17Default + implicit: + expr: kTestConfigOpt17Implicit + validator: + gte: + expr: kTestConfigOpt17Minimum + is_constexpr: false + lte: + expr: kTestConfigOpt17Maximum + is_constexpr: true + diff --git a/src/mongo/idl/server_parameter_with_storage_test.cpp b/src/mongo/idl/server_parameter_with_storage_test.cpp index 154fdfb210f..547e5ad23e5 100644 --- a/src/mongo/idl/server_parameter_with_storage_test.cpp +++ b/src/mongo/idl/server_parameter_with_storage_test.cpp @@ -244,5 +244,19 @@ TEST(IDLServerParameterWithStorage, startupStringRedacted) { ASSERT_EQ(obj[sp->name()].String(), "###"); } +TEST(IDLServerParameterWithStorage, startupIntWithExpressions) { + auto* sp = dynamic_cast<IDLServerParameterWithStorage<SPT::kStartupOnly, std::int32_t>*>( + getServerParameter("startupIntWithExpressions")); + ASSERT_EQ(test::gStartupIntWithExpressions, test::kStartupIntWithExpressionsDefault); + + ASSERT_NOT_OK(sp->setValue(test::kStartupIntWithExpressionsMinimum - 1)); + ASSERT_OK(sp->setValue(test::kStartupIntWithExpressionsMinimum)); + ASSERT_EQ(test::gStartupIntWithExpressions, test::kStartupIntWithExpressionsMinimum); + + ASSERT_NOT_OK(sp->setValue(test::kStartupIntWithExpressionsMaximum + 1)); + ASSERT_OK(sp->setValue(test::kStartupIntWithExpressionsMaximum)); + ASSERT_EQ(test::gStartupIntWithExpressions, test::kStartupIntWithExpressionsMaximum); +} + } // namespace } // namespace mongo diff --git a/src/mongo/idl/server_parameter_with_storage_test.h b/src/mongo/idl/server_parameter_with_storage_test.h index 164e1b5f5a5..3aedab52ac0 100644 --- a/src/mongo/idl/server_parameter_with_storage_test.h +++ b/src/mongo/idl/server_parameter_with_storage_test.h @@ -36,6 +36,10 @@ namespace mongo { namespace test { +constexpr std::int32_t kStartupIntWithExpressionsDefault = 100; +constexpr std::int32_t kStartupIntWithExpressionsMinimum = 10; +constexpr std::int32_t kStartupIntWithExpressionsMaximum = 1000; + // Storage for set parameter defined in server_parameter_with_storage.idl extern AtomicInt32 gStdIntPreallocated; diff --git a/src/mongo/idl/server_parameter_with_storage_test.idl b/src/mongo/idl/server_parameter_with_storage_test.idl index 9a39788fd68..3e310375f5b 100644 --- a/src/mongo/idl/server_parameter_with_storage_test.idl +++ b/src/mongo/idl/server_parameter_with_storage_test.idl @@ -31,9 +31,6 @@ global: cpp_includes: - "mongo/idl/server_parameter_with_storage_test.h" -imports: - - "mongo/idl/basic_types.idl" - server_parameters: stdIntPreallocated: set_at: [ startup, runtime ] @@ -73,3 +70,14 @@ server_parameters: cpp_vartype: "std::string" cpp_varname: gStartupStringRedacted redact: true + + startupIntWithExpressions: + set_at: startup + description: "Use of c++ expressions in default and validators" + cpp_vartype: "std::int32_t" + cpp_varname: gStartupIntWithExpressions + default: { expr: kStartupIntWithExpressionsDefault } + validator: + gte: { expr: kStartupIntWithExpressionsMinimum, is_constexpr: false } + lte: { expr: kStartupIntWithExpressionsMaximum, is_constexpr: true } + |