diff options
author | Moustafa Maher <m.maher@10gen.com> | 2021-03-09 01:50:26 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-03-12 02:27:57 +0000 |
commit | 0757d14ea960b2a30f2b84423551422e5980e41e (patch) | |
tree | 6f3eb48c1135ecd4e79806367a0c8c0af578387a /buildscripts/idl/tests | |
parent | f6787932d2711fe0c1c8380516328eb8ebef36d8 (diff) | |
download | mongo-0757d14ea960b2a30f2b84423551422e5980e41e.tar.gz |
SERVER-54771 Adding Array Type checking in idl_check_compatibility
Diffstat (limited to 'buildscripts/idl/tests')
9 files changed, 377 insertions, 1 deletions
diff --git a/buildscripts/idl/tests/compatibility_test_fail/abort/missing_array/command_parameter_no_array/command_parameter_no_array.idl b/buildscripts/idl/tests/compatibility_test_fail/abort/missing_array/command_parameter_no_array/command_parameter_no_array.idl new file mode 100644 index 00000000000..7a8c5dfc3ae --- /dev/null +++ b/buildscripts/idl/tests/compatibility_test_fail/abort/missing_array/command_parameter_no_array/command_parameter_no_array.idl @@ -0,0 +1,55 @@ +# Copyright (C) 2021-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" + +structs: + ArrayTypeStruct: + description: "Struct with ArrayType field." + fields: + ArrayCommandParameter: + type: array<string> + +commands: + ArrayCommandParameterNoArray: + description: "command will abort because the command field type is not of ArrayType while + the other is of ArrayType." + command_name: arrayCommandParameterNoArray + namespace: type + type: array<ArrayTypeStruct> + cpp_name: arrayCommandParameterNoArray + strict: true + api_version: "1" + fields: + parameterStruct: + type: ArrayTypeStruct + reply_type: ArrayTypeStruct
\ No newline at end of file diff --git a/buildscripts/idl/tests/compatibility_test_fail/abort/missing_array/command_parameter_with_array/command_parameter_with_array.idl b/buildscripts/idl/tests/compatibility_test_fail/abort/missing_array/command_parameter_with_array/command_parameter_with_array.idl new file mode 100644 index 00000000000..abe02f63150 --- /dev/null +++ b/buildscripts/idl/tests/compatibility_test_fail/abort/missing_array/command_parameter_with_array/command_parameter_with_array.idl @@ -0,0 +1,55 @@ +# Copyright (C) 2021-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" + +structs: + ArrayTypeStruct: + description: "Struct with ArrayType field." + fields: + ArrayCommandParameter: + type: array<string> + +commands: + ArrayCommandParameterNoArray: + description: "command will abort because the command field type of ArrayType while the other + is not of ArrayType." + command_name: arrayCommandParameterNoArray + namespace: type + type: array<ArrayTypeStruct> + cpp_name: arrayCommandParameterNoArray + strict: true + api_version: "1" + fields: + parameterStruct: + type: array<ArrayTypeStruct> + reply_type: ArrayTypeStruct
\ No newline at end of file diff --git a/buildscripts/idl/tests/compatibility_test_fail/abort/missing_array/command_type_no_array/command_type_no_array.idl b/buildscripts/idl/tests/compatibility_test_fail/abort/missing_array/command_type_no_array/command_type_no_array.idl new file mode 100644 index 00000000000..6d5302f7a2a --- /dev/null +++ b/buildscripts/idl/tests/compatibility_test_fail/abort/missing_array/command_type_no_array/command_type_no_array.idl @@ -0,0 +1,55 @@ +# Copyright (C) 2021-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" + +structs: + ArrayTypeStruct: + description: "Struct with ArrayType field." + fields: + ArrayCommandParameter: + type: array<string> + +commands: + ArrayCommandTypeErrorNoArray: + description: "command will abort because the command type is not of ArrayType while + the other is of ArrayType." + command_name: arrayCommandTypeErrorNoArray + namespace: type + type: ArrayTypeStruct + cpp_name: arrayCommandTypeErrorNoArray + strict: true + api_version: "1" + fields: + parameterStruct: + type: array<ArrayTypeStruct> + reply_type: ArrayTypeStruct
\ No newline at end of file diff --git a/buildscripts/idl/tests/compatibility_test_fail/abort/missing_array/command_type_with_array/command_type_with_array.idl b/buildscripts/idl/tests/compatibility_test_fail/abort/missing_array/command_type_with_array/command_type_with_array.idl new file mode 100644 index 00000000000..3ede8ce9c94 --- /dev/null +++ b/buildscripts/idl/tests/compatibility_test_fail/abort/missing_array/command_type_with_array/command_type_with_array.idl @@ -0,0 +1,55 @@ +# Copyright (C) 2021-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" + +structs: + ArrayTypeStruct: + description: "Struct with ArrayType field." + fields: + ArrayCommandParameter: + type: array<string> + +commands: + ArrayCommandTypeErrorNoArray: + description: "command will abort because the command type is of ArrayType while + the other is not of ArrayType." + command_name: arrayCommandTypeErrorNoArray + namespace: type + type: array<ArrayTypeStruct> + cpp_name: arrayCommandTypeErrorNoArray + strict: true + api_version: "1" + fields: + parameterStruct: + type: array<ArrayTypeStruct> + reply_type: ArrayTypeStruct
\ No newline at end of file diff --git a/buildscripts/idl/tests/compatibility_test_fail/new/compatibility_test_fail_new.idl b/buildscripts/idl/tests/compatibility_test_fail/new/compatibility_test_fail_new.idl index e160fb20202..5a337aa05b0 100644 --- a/buildscripts/idl/tests/compatibility_test_fail/new/compatibility_test_fail_new.idl +++ b/buildscripts/idl/tests/compatibility_test_fail/new/compatibility_test_fail_new.idl @@ -339,6 +339,12 @@ structs: stableRequiredTypeField: type: string + ArrayTypeStruct: + description: "Struct with ArrayType field." + fields: + ArrayCommandParameter: + type: array<string> + StructCommandParameterTypeRecursive: description: "This param struct type contains a field that is not compatible between the old and new versions" @@ -1459,3 +1465,31 @@ commands: privilege: resource_pattern: resourcePattern action_type: [actionType, actionTypeThree] + + ArrayCommandTypeError: + description: "new command will fail because the command type is an ArrayType of a type that + that isn't compatible with the old command." + command_name: arrayCommandTypeError + namespace: type + type: array<string> + cpp_name: arrayCommandTypeError + strict: true + api_version: "1" + fields: + parameterStruct: + type: array<ArrayTypeStruct> + reply_type: ArrayTypeStruct + + ArrayCommandParameterTypeError: + description: "new command will fail because the command paramter type are of ArrayType of a + type that is incompatible with the old command paramter type." + command_name: arrayCommandParameterTypeError + namespace: type + type: array<ArrayTypeStruct> + cpp_name: arrayCommandParameterTypeError + strict: true + api_version: "1" + fields: + parameterStruct: + type: array<StructType> + reply_type: ArrayTypeStruct diff --git a/buildscripts/idl/tests/compatibility_test_fail/old/compatibility_test_fail_old.idl b/buildscripts/idl/tests/compatibility_test_fail/old/compatibility_test_fail_old.idl index da250088e4b..106fb15076b 100644 --- a/buildscripts/idl/tests/compatibility_test_fail/old/compatibility_test_fail_old.idl +++ b/buildscripts/idl/tests/compatibility_test_fail/old/compatibility_test_fail_old.idl @@ -392,6 +392,12 @@ structs: type: variant: [int, string, StructCommandParameterTypeRecursive] + ArrayTypeStruct: + description: "Struct with ArrayType field." + fields: + ArrayCommandParameter: + type: array<string> + commands: invalidAPIVersionOld: description: "old command fails because of invalid API version" @@ -1447,3 +1453,31 @@ commands: privilege: resource_pattern: resourcePattern action_type: [actionType, actionTypeTwo] + + ArrayCommandTypeError: + description: "new command will fail because the command type is an ArrayType of a type that + that isn't compatible with the old command." + command_name: arrayCommandTypeError + namespace: type + type: array<ArrayTypeStruct> + cpp_name: arrayCommandTypeError + strict: true + api_version: "1" + fields: + parameterStruct: + type: array<ArrayTypeStruct> + reply_type: ArrayTypeStruct + + ArrayCommandParameterTypeError: + description: "new command will fail because the command paramter type are of ArrayType of a + type that is incompatible with the old command paramter type." + command_name: arrayCommandParameterTypeError + namespace: type + type: array<ArrayTypeStruct> + cpp_name: arrayCommandParameterTypeError + strict: true + api_version: "1" + fields: + parameterStruct: + type: array<ArrayTypeStruct> + reply_type: ArrayTypeStruct diff --git a/buildscripts/idl/tests/compatibility_test_pass/new/compatibility_test_pass_new.idl b/buildscripts/idl/tests/compatibility_test_pass/new/compatibility_test_pass_new.idl index c92ce46b2dc..accb2e7c43e 100644 --- a/buildscripts/idl/tests/compatibility_test_pass/new/compatibility_test_pass_new.idl +++ b/buildscripts/idl/tests/compatibility_test_pass/new/compatibility_test_pass_new.idl @@ -358,6 +358,12 @@ structs: type: variant: [bsonSerializationTypeAnyAllowed, StructFieldTypeRecursiveReplyTwo] + ArrayTypeStruct: + description: "Struct with ArrayType field." + fields: + ArrayCommandParameter: + type: array<string> + commands: testCommand: description: "new passing test command, there was no change from the old version" @@ -1123,3 +1129,17 @@ commands: privilege: resource_pattern: resourcePattern action_type: [actionTypeThree, actionTypeOne] + + ArrayCommand: + description: "new command will pass because the command type and the field type are of + ArrayType of a type that is compatible with the old command." + command_name: arrayCommand + namespace: type + type: array<ArrayTypeStruct> + cpp_name: arrayCommand + strict: true + api_version: "1" + fields: + parameterStruct: + type: array<ArrayTypeStruct> + reply_type: ArrayTypeStruct diff --git a/buildscripts/idl/tests/compatibility_test_pass/old/compatibility_test_pass_old.idl b/buildscripts/idl/tests/compatibility_test_pass/old/compatibility_test_pass_old.idl index 61b4fca1c79..795141862de 100644 --- a/buildscripts/idl/tests/compatibility_test_pass/old/compatibility_test_pass_old.idl +++ b/buildscripts/idl/tests/compatibility_test_pass/old/compatibility_test_pass_old.idl @@ -354,6 +354,12 @@ structs: type: variant: [intStringBoolToIntString, bsonSerializationTypeAnyAllowed, StructFieldTypeRecursiveReplyTwo] + ArrayTypeStruct: + description: "Struct with ArrayType field." + fields: + ArrayCommandParameter: + type: array<string> + commands: testCommand: description: "old passing test command" @@ -1119,3 +1125,17 @@ commands: privilege: resource_pattern: resourcePattern action_type: [actionTypeOne, actionTypeTwo, actionTypeThree] + + ArrayCommand: + description: "new command will pass because the command type and the field type are of + ArrayType of a type that is compatible with the old command." + command_name: arrayCommand + namespace: type + type: array<ArrayTypeStruct> + cpp_name: arrayCommand + strict: true + api_version: "1" + fields: + parameterStruct: + type: array<ArrayTypeStruct> + reply_type: ArrayTypeStruct diff --git a/buildscripts/idl/tests/test_compatibility.py b/buildscripts/idl/tests/test_compatibility.py index 7cf4d6bb245..43faba8b43f 100644 --- a/buildscripts/idl/tests/test_compatibility.py +++ b/buildscripts/idl/tests/test_compatibility.py @@ -83,6 +83,40 @@ class TestIDLCompatibilityChecker(unittest.TestCase): path.join(dir_path, "compatibility_test_fail/abort/invalid_command_parameter_type"), ["src"]) + with self.assertRaises(SystemExit): + idl_check_compatibility.check_compatibility( + path.join(dir_path, + "compatibility_test_fail/abort/missing_array/command_parameter_no_array"), + path.join( + dir_path, + "compatibility_test_fail/abort/missing_array/command_parameter_with_array"), + ["src"]) + + with self.assertRaises(SystemExit): + idl_check_compatibility.check_compatibility( + path.join( + dir_path, + "compatibility_test_fail/abort/missing_array/command_parameter_with_array"), + path.join(dir_path, + "compatibility_test_fail/abort/missing_array/command_parameter_no_array"), + ["src"]) + + with self.assertRaises(SystemExit): + idl_check_compatibility.check_compatibility( + path.join(dir_path, + "compatibility_test_fail/abort/missing_array/command_type_no_array"), + path.join(dir_path, + "compatibility_test_fail/abort/missing_array/command_type_with_array"), + ["src"]) + + with self.assertRaises(SystemExit): + idl_check_compatibility.check_compatibility( + path.join(dir_path, + "compatibility_test_fail/abort/missing_array/command_type_with_array"), + path.join(dir_path, + "compatibility_test_fail/abort/missing_array/command_type_no_array"), + ["src"]) + # pylint: disable=too-many-locals,too-many-statements def test_should_fail(self): """Tests that incompatible old and new IDL commands should fail.""" @@ -92,7 +126,7 @@ class TestIDLCompatibilityChecker(unittest.TestCase): path.join(dir_path, "compatibility_test_fail/new"), ["src"]) self.assertTrue(error_collection.has_errors()) - self.assertTrue(error_collection.count() == 97) + self.assertTrue(error_collection.count() == 100) invalid_api_version_new_error = error_collection.get_error_by_command_name( "invalidAPIVersionNew") @@ -574,6 +608,20 @@ class TestIDLCompatibilityChecker(unittest.TestCase): idl_compatibility_errors.ERROR_ID_COMMAND_TYPE_VALIDATORS_NOT_EQUAL) self.assertRegex( str(command_type_validators_not_equal_error), "commandTypeValidatorsNotEqual") + array_command_type_error = error_collection.get_error_by_command_name( + "arrayCommandTypeError") + self.assertTrue(array_command_type_error.error_id == + idl_compatibility_errors.ERROR_ID_NEW_COMMAND_TYPE_NOT_STRUCT) + self.assertRegex(str(array_command_type_error), "ArrayTypeStruct") + array_command_param_type_two_errors = error_collection.get_all_errors_by_command_name( + "arrayCommandParameterTypeError") + self.assertTrue(len(array_command_param_type_two_errors) == 2) + self.assertTrue(array_command_param_type_two_errors[0].error_id == + idl_compatibility_errors.ERROR_ID_REMOVED_COMMAND_PARAMETER) + self.assertRegex(str(array_command_param_type_two_errors[0]), "ArrayCommandParameter") + self.assertTrue(array_command_param_type_two_errors[1].error_id == + idl_compatibility_errors.ERROR_ID_ADDED_REQUIRED_COMMAND_PARAMETER) + self.assertRegex(str(array_command_param_type_two_errors[1]), "fieldOne") new_param_variant_not_superset_error = error_collection.get_error_by_command_name( "newParamVariantNotSuperset") |