summaryrefslogtreecommitdiff
path: root/src/mongo/idl
diff options
context:
space:
mode:
authorMark Benvenuto <mark.benvenuto@mongodb.com>2020-09-02 20:34:40 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-09-03 02:44:31 +0000
commitc6b83aca3aa431aff366c27d29eccac850758cef (patch)
treead1d32c0f69526b07272561eb92f5f89baae922b /src/mongo/idl
parent8e64b07e3bb363347ee2c11a56aba873365ed74a (diff)
downloadmongo-c6b83aca3aa431aff366c27d29eccac850758cef.tar.gz
SERVER-50367 Add IDL support for feature flags
Diffstat (limited to 'src/mongo/idl')
-rw-r--r--src/mongo/idl/SConscript2
-rw-r--r--src/mongo/idl/feature_flag_test.cpp60
-rw-r--r--src/mongo/idl/feature_flag_test.idl36
3 files changed, 98 insertions, 0 deletions
diff --git a/src/mongo/idl/SConscript b/src/mongo/idl/SConscript
index 28bcb2724b5..dd13816c007 100644
--- a/src/mongo/idl/SConscript
+++ b/src/mongo/idl/SConscript
@@ -32,11 +32,13 @@ env.CppUnitTest(
target='idl_test',
source=[
'config_option_test.cpp',
+ 'feature_flag_test.cpp',
'idl_test.cpp',
'server_parameter_specialized_test.cpp',
'server_parameter_with_storage_test.cpp',
env.Idlc('config_option_no_init_test.idl')[0],
env.Idlc('config_option_test.idl')[0],
+ env.Idlc('feature_flag_test.idl')[0],
env.Idlc('server_parameter_specialized_test.idl')[0],
env.Idlc('server_parameter_with_storage_test.idl')[0],
env.Idlc('unittest.idl')[0],
diff --git a/src/mongo/idl/feature_flag_test.cpp b/src/mongo/idl/feature_flag_test.cpp
new file mode 100644
index 00000000000..cb111756272
--- /dev/null
+++ b/src/mongo/idl/feature_flag_test.cpp
@@ -0,0 +1,60 @@
+/**
+ * Copyright (C) 2020-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.
+ */
+
+#include "mongo/platform/basic.h"
+
+#include "mongo/idl/feature_flag_test_gen.h"
+#include "mongo/unittest/unittest.h"
+
+namespace mongo {
+
+namespace {
+
+ServerParameter* getServerParameter(const std::string& name) {
+ const auto& spMap = ServerParameterSet::getGlobal()->getMap();
+ const auto& spIt = spMap.find(name);
+ ASSERT(spIt != spMap.end());
+
+ auto* sp = spIt->second;
+ ASSERT(sp);
+ return sp;
+}
+
+TEST(IDLFeatureFlag, Basic) {
+ // true is set by "default" attribute in the IDL file.
+ ASSERT_EQ(feature_flags::gFeatureFlagToaster, true);
+
+ auto* featureFlagToaster = getServerParameter("featureFlagToaster");
+ ASSERT_OK(featureFlagToaster->setFromString("false"));
+ ASSERT_EQ(feature_flags::gFeatureFlagToaster, false);
+ ASSERT_NOT_OK(featureFlagToaster->setFromString("alpha"));
+}
+
+} // namespace
+} // namespace mongo
diff --git a/src/mongo/idl/feature_flag_test.idl b/src/mongo/idl/feature_flag_test.idl
new file mode 100644
index 00000000000..c756ca5a90f
--- /dev/null
+++ b/src/mongo/idl/feature_flag_test.idl
@@ -0,0 +1,36 @@
+# Copyright (C) 2020-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.
+#
+
+global:
+ cpp_namespace: "mongo::feature_flags"
+
+feature_flags:
+ featureFlagToaster:
+ description: "Create a feature flag"
+ cpp_varname: gFeatureFlagToaster
+ default: true