summaryrefslogtreecommitdiff
path: root/src/mongo/idl
diff options
context:
space:
mode:
authorSara Golemon <sara.golemon@mongodb.com>2018-11-25 18:44:04 +0000
committerSara Golemon <sara.golemon@mongodb.com>2018-11-29 19:51:25 +0000
commit3560708835e0d0deeed226168a29ab27a49bdde8 (patch)
tree850f638147952bd06dc76648d3fb272143f83c75 /src/mongo/idl
parent35f465029fdccee1a3b7e3b8fb91a2ea75b9aca7 (diff)
downloadmongo-3560708835e0d0deeed226168a29ab27a49bdde8.tar.gz
SERVER-38279 Add condition clause to set parameter and config option definitions
Diffstat (limited to 'src/mongo/idl')
-rw-r--r--src/mongo/idl/config_option_test.cpp20
-rw-r--r--src/mongo/idl/config_option_test.h39
-rw-r--r--src/mongo/idl/config_option_test.idl22
-rw-r--r--src/mongo/idl/server_parameter.h2
-rw-r--r--src/mongo/idl/server_parameter_test.idl18
5 files changed, 100 insertions, 1 deletions
diff --git a/src/mongo/idl/config_option_test.cpp b/src/mongo/idl/config_option_test.cpp
index 31824b893bf..3c2682f68cf 100644
--- a/src/mongo/idl/config_option_test.cpp
+++ b/src/mongo/idl/config_option_test.cpp
@@ -42,6 +42,8 @@ namespace mongo {
namespace test {
namespace moe = ::mongo::optionenvironment;
+bool gEnableTestConfigOpt14 = true;
+bool gEnableTestConfigOpt15 = false;
namespace {
@@ -89,6 +91,8 @@ MONGO_STARTUP_OPTIONS_PARSE(ConfigOption)(InitializerContext*) {
"8",
"--testConfigOpt12",
"command-line option",
+ "--testConfigOpt14",
+ "set14",
};
return parseArgv(argv, &moe::startupOptionsParsed);
}
@@ -365,6 +369,22 @@ TEST(ConfigOption, Opt13) {
ASSERT_OPTION_SET<std::string>(parsedShort, "test.config.opt13", "short");
}
+TEST(ConfigOption, Opt14) {
+ ASSERT_OPTION_SET<std::string>(moe::startupOptionsParsed, "test.config.opt14", "set14");
+ ASSERT_EQ(gTestConfigOpt14, "set14");
+}
+
+TEST(ConfigOption, Opt15) {
+ ASSERT_OPTION_NOT_SET<std::string>(moe::startupOptionsParsed, "test.config.opt15");
+
+ // Fails because the option was never declared.
+ moe::Environment parseFail;
+ ASSERT_NOT_OK(parseArgv({"mongod", "--testConfigOpt15", "set15"}, &parseFail));
+
+ // Variable is declared.
+ ASSERT_EQ(gTestConfigOpt15, "");
+}
+
} // namespace
} // namespace test
diff --git a/src/mongo/idl/config_option_test.h b/src/mongo/idl/config_option_test.h
new file mode 100644
index 00000000000..e0de0b68c03
--- /dev/null
+++ b/src/mongo/idl/config_option_test.h
@@ -0,0 +1,39 @@
+/**
+ * Copyright (C) 2018-present MongoDB, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the Server Side Public License, version 1,
+ * as published by MongoDB, Inc.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * Server Side Public License for more details.
+ *
+ * You should have received a copy of the Server Side Public License
+ * along with this program. If not, see
+ * <http://www.mongodb.com/licensing/server-side-public-license>.
+ *
+ * As a special exception, the copyright holders give permission to link the
+ * code of portions of this program with the OpenSSL library under certain
+ * conditions as described in each individual source file and distribute
+ * linked combinations including the program with the OpenSSL library. You
+ * must comply with the Server Side Public License in all respects for
+ * all of the code used other than as permitted herein. If you modify file(s)
+ * with this exception, you may extend this exception to your version of the
+ * file(s), but you are not obligated to do so. If you do not wish to do so,
+ * delete this exception statement from your version. If you delete this
+ * exception statement from all source files in the program, then also delete
+ * it in the license file.
+ */
+
+#pragma once
+
+namespace mongo {
+namespace test {
+
+extern bool gEnableTestConfigOpt14;
+extern bool gEnableTestConfigOpt15;
+
+} // namespace test
+} // namespace mongo
diff --git a/src/mongo/idl/config_option_test.idl b/src/mongo/idl/config_option_test.idl
index 6c85b939421..4a6ede7f71d 100644
--- a/src/mongo/idl/config_option_test.idl
+++ b/src/mongo/idl/config_option_test.idl
@@ -30,6 +30,7 @@ global:
cpp_namespace: "mongo::test"
cpp_includes:
- "mongo/idl/server_parameter_with_storage_test.h"
+ - "mongo/idl/config_option_test.h"
configs:
initializer_name: TestConfigs
@@ -152,3 +153,24 @@ configs:
single_name: o
arg_vartype: String
source: cli
+
+ "test.config.opt14":
+ description: "Test with preprocessor and runtime conditions positive"
+ short_name: testConfigOpt14
+ arg_vartype: String
+ source: cli
+ cpp_vartype: std::string
+ cpp_varname: gTestConfigOpt14
+ condition:
+ preprocessor: "1 == 1"
+ expr: gEnableTestConfigOpt14
+
+ "test.config.opt15":
+ description: "Test with runtime condition negative"
+ short_name: testConfigOpt15
+ arg_vartype: String
+ source: cli
+ cpp_vartype: std::string
+ cpp_varname: gTestConfigOpt15
+ condition:
+ expr: gEnableTestConfigOpt15
diff --git a/src/mongo/idl/server_parameter.h b/src/mongo/idl/server_parameter.h
index 5022bb00327..12b1a0582a5 100644
--- a/src/mongo/idl/server_parameter.h
+++ b/src/mongo/idl/server_parameter.h
@@ -108,7 +108,7 @@ protected:
/**
* Proxy instance for deprecated aliases of set parameters.
*/
-class IDLServerParameterDeprecatedAlias : ServerParameter {
+class IDLServerParameterDeprecatedAlias : public ServerParameter {
public:
IDLServerParameterDeprecatedAlias(StringData name, ServerParameter* sp);
diff --git a/src/mongo/idl/server_parameter_test.idl b/src/mongo/idl/server_parameter_test.idl
index c6c1f6eab64..9d3ce9d13d9 100644
--- a/src/mongo/idl/server_parameter_test.idl
+++ b/src/mongo/idl/server_parameter_test.idl
@@ -48,3 +48,21 @@ server_parameters:
description: "Basic test using default fromBSON callback."
append_bson: "customSettingAppendBSON"
from_string: "customSettingFromString"
+
+ customSettingWithPositiveConditions:
+ set_at: startup
+ description: "Testing that conditions are created."
+ append_bson: "customSettingAppendBSON"
+ from_string: "customSettingFromString"
+ condition:
+ expr: "true"
+ preprocessor: "1 == 1"
+
+ customSettingWithNegativeConditions:
+ set_at: startup
+ description: "Testing that conditions are created."
+ append_bson: "customSettingAppendBSON"
+ from_string: "customSettingFromString"
+ condition:
+ expr: "false"
+ preprocessor: "1 == 0"