From cb4a75a2252263ccbf435306829b935f412e718b Mon Sep 17 00:00:00 2001 From: amstee Date: Thu, 23 May 2024 12:00:06 +0100 Subject: [PATCH 1/3] bug: adding unit test for java_multiple_files --- .../test_protobuf_binary_serialization.py | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/unit/test_protobuf_binary_serialization.py b/tests/unit/test_protobuf_binary_serialization.py index 06d1def96..dcd1c5be3 100644 --- a/tests/unit/test_protobuf_binary_serialization.py +++ b/tests/unit/test_protobuf_binary_serialization.py @@ -51,11 +51,36 @@ "CgdkZWZhdWx0Ig8KA0tleRIICgJpZBgBKAUiLQoDRG9nEgoKBG5hbWUYASgJEgwKBndlaWdodBgCKAUSDAoEdG95cxgEIAMoCWIGcHJvdG8z" ) +schema_serialized2 = ( + "CiZwcm90by90ZWNoL2Rvam8vZHNwL3YxL2V2ZW50X2tleS5wcm90bxIQdGVjaC5kb2pvLmRzcC52MSIaCghFdmVudEtleRIOCgJpZBgBIAEoCVI" + + "CaWRCiAEKFGNvbS50ZWNoLmRvam8uZHNwLnYxQg1FdmVudEtleVByb3RvUAGiAgNURESqAhBUZWNoLkRvam8uRHNwLlYxygIQVGVjaFxEb2pvXER" + + "zcFxWMeICHFRlY2hcRG9qb1xEc3BcVjFcR1BCTWV0YWRhdGHqAhNUZWNoOjpEb2pvOjpEc3A6OlYxYgZwcm90bzM=" +) + +schema_plain2 = """\ +syntax = "proto3"; +package tech.dojo.dsp.v1; + +option java_package = "com.tech.dojo.dsp.v1"; +option java_outer_classname = "EventKeyProto"; +option java_multiple_files = true; +option objc_class_prefix = "TDD"; +option csharp_namespace = "Tech.Dojo.Dsp.V1"; +option php_namespace = "Tech\\Dojo\\Dsp\\V1"; +option php_metadata_namespace = "Tech\\Dojo\\Dsp\\V1\\GPBMetadata"; +option ruby_package = "Tech::Dojo::Dsp::V1"; + +message EventKey { + string id = 1; +} +""" + @pytest.mark.parametrize( "schema_plain,schema_serialized", [ (schema_plain1, schema_serialized1), + (schema_plain2, schema_serialized2), (schema_protobuf_plain, schema_protobuf_plain_bin), (schema_protobuf_order_after, schema_protobuf_order_after_bin), (schema_protobuf_nested_message4, schema_protobuf_nested_message4_bin), From 049c2e42fcb2b97390f29093d0bd67faef44db57 Mon Sep 17 00:00:00 2001 From: Jarkko Jaakola Date: Fri, 24 May 2024 10:29:52 +0300 Subject: [PATCH 2/3] fix: Format boolean options to lowercase string in schema --- karapace/protobuf/option_element.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/karapace/protobuf/option_element.py b/karapace/protobuf/option_element.py index 9ff50fe8e..70622d5ef 100644 --- a/karapace/protobuf/option_element.py +++ b/karapace/protobuf/option_element.py @@ -31,10 +31,14 @@ def __init__(self, name: str, kind: Kind, value, is_parenthesized: bool = False) self.formattedName = f"({self.name})" if is_parenthesized else self.name def to_schema(self) -> str: - aline = None + aline = "" if self.kind == self.Kind.STRING: aline = f'{self.formattedName} = "{self.value}"' - elif self.kind in [self.Kind.BOOLEAN, self.Kind.NUMBER, self.Kind.ENUM]: + elif self.kind == self.Kind.BOOLEAN: + aline = f"{self.formattedName} = {str(self.value).lower()}" + elif self.kind == self.Kind.NUMBER: + aline = f"{self.formattedName} = {self.value}" + elif self.kind == self.Kind.ENUM: aline = f"{self.formattedName} = {self.value}" elif self.kind == self.Kind.OPTION: aline = f"{self.formattedName}.{try_to_schema(self.value)}" @@ -42,6 +46,8 @@ def to_schema(self) -> str: aline = [f"{self.formattedName} = {{\n", self.format_option_map(self.value), "}"] elif self.kind == self.Kind.LIST: aline = [f"{self.formattedName} = ", self.append_options(self.value)] + else: + raise ValueError("Unknown value Kind.") if isinstance(aline, list): return "".join(aline) From da8a0b6ea16931c6714605f396efbb6c4c879bcb Mon Sep 17 00:00:00 2001 From: Jarkko Jaakola Date: Fri, 24 May 2024 10:41:34 +0300 Subject: [PATCH 3/3] fix: correct test data to escape php_namespace option with two backslashes --- tests/unit/test_protobuf_binary_serialization.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/test_protobuf_binary_serialization.py b/tests/unit/test_protobuf_binary_serialization.py index dcd1c5be3..6950066d3 100644 --- a/tests/unit/test_protobuf_binary_serialization.py +++ b/tests/unit/test_protobuf_binary_serialization.py @@ -66,8 +66,8 @@ option java_multiple_files = true; option objc_class_prefix = "TDD"; option csharp_namespace = "Tech.Dojo.Dsp.V1"; -option php_namespace = "Tech\\Dojo\\Dsp\\V1"; -option php_metadata_namespace = "Tech\\Dojo\\Dsp\\V1\\GPBMetadata"; +option php_namespace = "Tech\\\\Dojo\\\\Dsp\\\\V1"; +option php_metadata_namespace = "Tech\\\\Dojo\\\\Dsp\\\\V1\\\\GPBMetadata"; option ruby_package = "Tech::Dojo::Dsp::V1"; message EventKey {