From 19e738060638983510632b4bb9efdf3493b097ec Mon Sep 17 00:00:00 2001 From: Elia Migliore Date: Wed, 18 Oct 2023 15:53:10 +0200 Subject: [PATCH] test: add test that checks new message addition are valid added tests that need to succed or fail based on the schema evolution logic --- ...est_dependencies_compatibility_protobuf.py | 167 ++++++++++++++++-- 1 file changed, 154 insertions(+), 13 deletions(-) diff --git a/tests/integration/test_dependencies_compatibility_protobuf.py b/tests/integration/test_dependencies_compatibility_protobuf.py index 8e5f11a1d..0214d6acf 100644 --- a/tests/integration/test_dependencies_compatibility_protobuf.py +++ b/tests/integration/test_dependencies_compatibility_protobuf.py @@ -7,6 +7,7 @@ from karapace.client import Client from karapace.protobuf.kotlin_wrapper import trim_margin +from karapace.typing import Subject from tests.utils import create_subject_name_factory import pytest @@ -672,7 +673,14 @@ async def test_protobuf_customer_update_when_having_references(registry_async_cl assert res.status_code == 200 -async def test_protobuf_schema_compatibility_full_path_renaming(): +async def test_protobuf_schema_compatibility_full_path_renaming(registry_async_client: Client) -> None: + subject_dependency = Subject("dependency") + subject_entity = Subject("entity") + + for subject in [subject_dependency, subject_entity]: + res = await registry_async_client.put(f"config/{subject}", json={"compatibility": "FULL"}) + assert res.status_code == 200 + dependency = """\ package "my.awesome.customer.request"; message RequestId { @@ -694,11 +702,53 @@ async def test_protobuf_schema_compatibility_full_path_renaming(): }\ """ - # placeholder for a real test - assert dependency + original_full_path + evolved_partial_path != "" + # registering the dependency + body = {"schemaType": "PROTOBUF", "schema": dependency} + res = await registry_async_client.post(f"subjects/{subject_dependency}/versions", json=body) + assert res.status_code == 200 + + # registering the entity + + body = { + "schemaType": "PROTOBUF", + "schema": original_full_path, + "references": [ + { + "name": "place.proto", + "subject": subject_dependency, + "version": -1, + } + ], + } + res = await registry_async_client.post(f"subjects/{subject_entity}/versions", json=body) + assert res.status_code == 200 + + # registering the evolved entity + + body = { + "schemaType": "PROTOBUF", + "schema": evolved_partial_path, + "references": [ + { + "name": "place.proto", + "subject": subject_dependency, + "version": -1, + } + ], + } + res = await registry_async_client.post(f"subjects/{subject_entity}/versions", json=body) + assert res.status_code == 200 + + +async def test_protobuf_schema_compatibility_partial_path_renaming(registry_async_client: Client) -> None: + subject_dependency = Subject("dependency") + subject_entity = Subject("entity") + + for subject in [subject_dependency, subject_entity]: + res = await registry_async_client.put(f"config/{subject}", json={"compatibility": "FULL"}) + assert res.status_code == 200 -async def test_protobuf_schema_compatibility_partial_path_renaming(): dependency = """\ package "my.awesome.customer.request"; message RequestId { @@ -720,19 +770,62 @@ async def test_protobuf_schema_compatibility_partial_path_renaming(): }\ """ - # placeholder for a real test - assert dependency + original_partial_path + evolved_full_path != "" + # registering the dependency + body = {"schemaType": "PROTOBUF", "schema": dependency} + res = await registry_async_client.post(f"subjects/{subject_dependency}/versions", json=body) + assert res.status_code == 200 -async def test_protobuf_schema_compatibility_import_renaming_should_fail(): - dependency = """\ + # registering the entity + + body = { + "schemaType": "PROTOBUF", + "schema": original_partial_path, + "references": [ + { + "name": "place.proto", + "subject": subject_dependency, + "version": -1, + } + ], + } + res = await registry_async_client.post(f"subjects/{subject_entity}/versions", json=body) + assert res.status_code == 200 + + # registering the evolved entity + + body = { + "schemaType": "PROTOBUF", + "schema": evolved_full_path, + "references": [ + { + "name": "place.proto", + "subject": subject_dependency, + "version": -1, + } + ], + } + res = await registry_async_client.post(f"subjects/{subject_entity}/versions", json=body) + assert res.status_code == 200 + + +async def test_protobuf_schema_compatibility_import_renaming_should_fail(registry_async_client: Client) -> None: + first_subject_dependency = Subject("first_dependency") + second_subject_dependency = Subject("second_dependency") + subject_entity = Subject("entity") + + for subject in [first_subject_dependency, second_subject_dependency, subject_entity]: + res = await registry_async_client.put(f"config/{subject}", json={"compatibility": "FULL"}) + assert res.status_code == 200 + + first_dependency = """\ package "my.awesome.customer.request"; message RequestId { string request_id = 1; }\ """ - updated_dependency = """\ + second_dependency = """\ package "awesome.customer.request"; message RequestId { string request_id = 1; @@ -757,9 +850,57 @@ async def test_protobuf_schema_compatibility_import_renaming_should_fail(): }\ """ - # placeholder for a real test - assert dependency + original_partial_path + evolved_partial_path + updated_dependency != "" - # this should fail because now it's referring to the other object. + # registering the first dependency + body = {"schemaType": "PROTOBUF", "schema": first_dependency} + res = await registry_async_client.post(f"subjects/{first_subject_dependency}/versions", json=body) + + assert res.status_code == 200 + + # registering the second dependency + body = {"schemaType": "PROTOBUF", "schema": second_dependency} + res = await registry_async_client.post(f"subjects/{second_subject_dependency}/versions", json=body) + + assert res.status_code == 200 + + # registering the entity + body = { + "schemaType": "PROTOBUF", + "schema": original_partial_path, + "references": [ + { + "name": f"{first_subject_dependency}.proto", + "subject": first_subject_dependency, + "version": -1, + }, + { + "name": f"{second_subject_dependency}.proto", + "subject": second_subject_dependency, + "version": -1, + } + ], + } + res = await registry_async_client.post(f"subjects/{subject_entity}/versions", json=body) + assert res.status_code == 200 + + # registering the evolved entity + body = { + "schemaType": "PROTOBUF", + "schema": evolved_partial_path, + "references": [ + { + "name": f"{first_subject_dependency}.proto", + "subject": first_subject_dependency, + "version": -1, + }, + { + "name": f"{second_subject_dependency}.proto", + "subject": second_subject_dependency, + "version": -1, + } + ], + } + res = await registry_async_client.post(f"subjects/{subject_entity}/versions", json=body) + assert res.status_code != 200 @pytest.mark.parametrize("compatibility,expected_to_fail", [("FULL", True), ("FORWARD", True), ("BACKWARD", False)]) @@ -853,7 +994,7 @@ async def test_protobuf_schema_update_add_message( assert res.status_code == 409 assert res.json() == { "message": f"Incompatible schema, compatibility_mode={compatibility} Incompatible modification " - f"Modification.MESSAGE_DROP found", + f"Modification.MESSAGE_DROP found", "error_code": 409, } else: