summaryrefslogtreecommitdiff
path: root/buildscripts/idl/tests
diff options
context:
space:
mode:
authorHuayu Ouyang <huayu.ouyang@mongodb.com>2022-01-25 20:10:14 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-01-25 21:00:19 +0000
commitb6dc9c4baa67a0565668fc0f2fc7567e10390725 (patch)
tree439d3959e0fef152893460eda6f328a95295e64f /buildscripts/idl/tests
parent526a557b06c4335abd63c15c92a5a78a65587a2c (diff)
downloadmongo-b6dc9c4baa67a0565668fc0f2fc7567e10390725.tar.gz
SERVER-62621 IDL compatibility checker should check brand new commands
Diffstat (limited to 'buildscripts/idl/tests')
-rw-r--r--buildscripts/idl/tests/compatibility_test_fail/newly_added_commands/newly_added_commands.idl124
-rw-r--r--buildscripts/idl/tests/test_compatibility.py59
2 files changed, 183 insertions, 0 deletions
diff --git a/buildscripts/idl/tests/compatibility_test_fail/newly_added_commands/newly_added_commands.idl b/buildscripts/idl/tests/compatibility_test_fail/newly_added_commands/newly_added_commands.idl
new file mode 100644
index 00000000000..c07063ec61d
--- /dev/null
+++ b/buildscripts/idl/tests/compatibility_test_fail/newly_added_commands/newly_added_commands.idl
@@ -0,0 +1,124 @@
+# Copyright (C) 2022-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"
+
+imports:
+ - "mongo/idl/basic_types.idl"
+ - "../buildscripts/idl/tests/compatibility_test_fail/new/imports.idl"
+
+types:
+ bsonSerializationTypeAny:
+ bson_serialization_type:
+ - int
+ - any
+ description: "The bson_serialization_type contains 'any'"
+ cpp_type: "std::int32_t"
+
+structs:
+ NewStructFieldNoUnstableField:
+ description: "new struct field has no unstable field specified"
+ fields:
+ newStructFieldNoUnstableField:
+ type: bool
+
+ NewStructFieldTypeContainsAny:
+ description: "new struct field type has bson_serialization_type with 'any'"
+ fields:
+ newStructFieldTypeContainsAny:
+ type: bsonSerializationTypeAny
+ unstable: false
+
+commands:
+ newCommandParameterNoUnstableField:
+ description: "newly added command has a parameter without the unstable field specified"
+ command_name: newCommandParameterNoUnstableField
+ namespace: ignored
+ cpp_name: newCommandParameterNoUnstableField
+ strict: true
+ api_version: "1"
+ fields:
+ flag1:
+ type: bool
+ reply_type: OkReply
+
+ newCommandReplyNoUnstableField:
+ description: "newly added command has a reply field without the unstable field specified"
+ command_name: newCommandReplyNoUnstableField
+ namespace: ignored
+ cpp_name: newCommandReplyNoUnstableField
+ strict: true
+ api_version: "1"
+ reply_type: NewStructFieldNoUnstableField
+
+ newCommandTypeStructFieldNoUnstableField:
+ description: "newly added command has a command type struct field without the unstable
+ field specified"
+ command_name: newCommandTypeStructFieldNoUnstableField
+ namespace: type
+ type: NewStructFieldNoUnstableField
+ cpp_name: newCommandTypeStructFieldNoUnstableField
+ strict: true
+ api_version: "1"
+ reply_type: OkReply
+
+ newCommandParameterBsonSerializationTypeAny:
+ description: "newly added command has a parameter type that has bson_serialization_type
+ with 'any'"
+ command_name: newCommandParameterBsonSerializationTypeAny
+ namespace: ignored
+ cpp_name: newCommandParameterBsonSerializationTypeAny
+ strict: true
+ api_version: "1"
+ fields:
+ flag1:
+ type: bsonSerializationTypeAny
+ unstable: false
+ reply_type: OkReply
+
+ newCommandReplyBsonSerializationTypeAny:
+ description: "newly added command has a reply field type that has bson_serialization_type
+ with 'any'"
+ command_name: newCommandReplyBsonSerializationTypeAny
+ namespace: ignored
+ cpp_name: newCommandReplyBsonSerializationTypeAny
+ strict: true
+ api_version: "1"
+ reply_type: NewStructFieldTypeContainsAny
+
+ newCommandTypeStructFieldBsonSerializationTypeAny:
+ description: "newly added command has a command struct field type that has
+ bson_serialization_type with 'any'"
+ command_name: newCommandTypeStructFieldBsonSerializationTypeAny
+ namespace: type
+ type: NewStructFieldTypeContainsAny
+ cpp_name: newCommandTypeStructFieldBsonSerializationTypeAny
+ strict: true
+ api_version: "1"
+ reply_type: OkReply
diff --git a/buildscripts/idl/tests/test_compatibility.py b/buildscripts/idl/tests/test_compatibility.py
index 21c6492de46..7bd80713869 100644
--- a/buildscripts/idl/tests/test_compatibility.py
+++ b/buildscripts/idl/tests/test_compatibility.py
@@ -81,6 +81,65 @@ class TestIDLCompatibilityChecker(unittest.TestCase):
path.join(dir_path, "compatibility_test_fail/abort/invalid_command_parameter_type"),
["src"], ["src"])
+ # pylint: disable=invalid-name
+ def test_newly_added_commands_should_fail(self):
+ """Tests that incompatible newly added commands should fail."""
+ dir_path = path.dirname(path.realpath(__file__))
+ error_collection = idl_check_compatibility.check_compatibility(
+ path.join(dir_path, "compatibility_test_fail/newly_added_commands"),
+ path.join(dir_path, "compatibility_test_fail/newly_added_commands"), ["src"], ["src"])
+
+ self.assertTrue(error_collection.has_errors())
+ self.assertEqual(error_collection.count(), 6)
+
+ new_parameter_no_unstable_field_error = error_collection.get_error_by_command_name(
+ "newCommandParameterNoUnstableField")
+ self.assertTrue(new_parameter_no_unstable_field_error.error_id ==
+ idl_compatibility_errors.ERROR_ID_NEW_PARAMETER_REQUIRES_UNSTABLE)
+ self.assertRegex(
+ str(new_parameter_no_unstable_field_error), "newCommandParameterNoUnstableField")
+
+ new_reply_no_unstable_field_error = error_collection.get_error_by_command_name(
+ "newCommandReplyNoUnstableField")
+ self.assertTrue(new_reply_no_unstable_field_error.error_id ==
+ idl_compatibility_errors.ERROR_ID_NEW_REPLY_FIELD_REQUIRES_UNSTABLE)
+ self.assertRegex(str(new_reply_no_unstable_field_error), "newCommandReplyNoUnstableField")
+
+ new_command_type_struct_no_unstable_field_error = error_collection.get_error_by_command_name(
+ "newCommandTypeStructFieldNoUnstableField")
+ self.assertTrue(new_command_type_struct_no_unstable_field_error.error_id ==
+ idl_compatibility_errors.ERROR_ID_NEW_COMMAND_TYPE_FIELD_REQUIRES_UNSTABLE)
+ self.assertRegex(
+ str(new_command_type_struct_no_unstable_field_error),
+ "newCommandTypeStructFieldNoUnstableField")
+
+ new_parameter_bson_serialization_type_any_error = error_collection.get_error_by_command_name(
+ "newCommandParameterBsonSerializationTypeAny")
+ self.assertTrue(
+ new_parameter_bson_serialization_type_any_error.error_id == idl_compatibility_errors.
+ ERROR_ID_COMMAND_PARAMETER_BSON_SERIALIZATION_TYPE_ANY_NOT_ALLOWED)
+ self.assertRegex(
+ str(new_parameter_bson_serialization_type_any_error),
+ "newCommandParameterBsonSerializationTypeAny")
+
+ new_reply_bson_serialization_type_any_error = error_collection.get_error_by_command_name(
+ "newCommandReplyBsonSerializationTypeAny")
+ self.assertTrue(
+ new_reply_bson_serialization_type_any_error.error_id ==
+ idl_compatibility_errors.ERROR_ID_REPLY_FIELD_BSON_SERIALIZATION_TYPE_ANY_NOT_ALLOWED)
+ self.assertRegex(
+ str(new_reply_bson_serialization_type_any_error),
+ "newCommandReplyBsonSerializationTypeAny")
+
+ new_command_type_struct_bson_serialization_type_any_error = error_collection.get_error_by_command_name(
+ "newCommandTypeStructFieldBsonSerializationTypeAny")
+ self.assertTrue(
+ new_command_type_struct_bson_serialization_type_any_error.error_id ==
+ idl_compatibility_errors.ERROR_ID_COMMAND_TYPE_BSON_SERIALIZATION_TYPE_ANY_NOT_ALLOWED)
+ self.assertRegex(
+ str(new_command_type_struct_bson_serialization_type_any_error),
+ "newCommandTypeStructFieldBsonSerializationTypeAny")
+
# pylint: disable=too-many-locals,too-many-statements,invalid-name
def test_should_fail(self):
"""Tests that incompatible old and new IDL commands should fail."""