From 10f02a907376a42d9e2c2f3c5cca33011bb30e0a Mon Sep 17 00:00:00 2001 From: Salomon Popp Date: Wed, 11 Oct 2023 10:59:04 +0200 Subject: [PATCH] Print details on connector name mismatch error (#369) --- .gitignore | 1 + kpops/components/base_components/kafka_connector.py | 2 +- tests/components/test_kafka_connector.py | 11 +++++++++-- .../pipeline-with-env-defaults/defaults.yaml | 4 ++-- .../defaults_development.yaml | 2 +- 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index db58e072b..7724b5bab 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ pipelines/ defaults/ site/ +scratch* diff --git a/kpops/components/base_components/kafka_connector.py b/kpops/components/base_components/kafka_connector.py index 96ee68041..f77588401 100644 --- a/kpops/components/base_components/kafka_connector.py +++ b/kpops/components/base_components/kafka_connector.py @@ -87,7 +87,7 @@ def connector_config_should_have_component_name( component_name = values["prefix"] + values["name"] connector_name: str | None = app.get("name") if connector_name is not None and connector_name != component_name: - msg = "Connector name should be the same as component name" + msg = f"Connector name '{connector_name}' should be the same as component name '{component_name}'" raise ValueError(msg) app["name"] = component_name return app diff --git a/tests/components/test_kafka_connector.py b/tests/components/test_kafka_connector.py index 2adf867da..98771d4af 100644 --- a/tests/components/test_kafka_connector.py +++ b/tests/components/test_kafka_connector.py @@ -1,3 +1,4 @@ +import re from pathlib import Path from unittest.mock import MagicMock @@ -85,7 +86,10 @@ def test_connector_config_name_override( assert connector.app.name == CONNECTOR_FULL_NAME with pytest.raises( - ValueError, match="Connector name should be the same as component name" + ValueError, + match=re.escape( + f"Connector name 'different-name' should be the same as component name '{CONNECTOR_FULL_NAME}'" + ), ): KafkaConnector( name=CONNECTOR_NAME, @@ -96,7 +100,10 @@ def test_connector_config_name_override( ) with pytest.raises( - ValueError, match="Connector name should be the same as component name" + ValueError, + match=re.escape( + f"Connector name '' should be the same as component name '{CONNECTOR_FULL_NAME}'" + ), ): KafkaConnector( name=CONNECTOR_NAME, diff --git a/tests/pipeline/resources/pipeline-with-env-defaults/defaults.yaml b/tests/pipeline/resources/pipeline-with-env-defaults/defaults.yaml index 2564e0012..639c176e5 100644 --- a/tests/pipeline/resources/pipeline-with-env-defaults/defaults.yaml +++ b/tests/pipeline/resources/pipeline-with-env-defaults/defaults.yaml @@ -1,5 +1,5 @@ kubernetes-app: - name: "${component_type}" + name: ${component_type} namespace: example-namespace kafka-app: app: @@ -24,7 +24,7 @@ streams-app: # inherits from kafka-app cleanup.policy: compact,delete kafka-connector: - name: "sink-connector" + name: sink-connector app: batch.size: "2000" behavior.on.malformed.documents: "warn" diff --git a/tests/pipeline/resources/pipeline-with-env-defaults/defaults_development.yaml b/tests/pipeline/resources/pipeline-with-env-defaults/defaults_development.yaml index 035691c2e..c7b863a92 100644 --- a/tests/pipeline/resources/pipeline-with-env-defaults/defaults_development.yaml +++ b/tests/pipeline/resources/pipeline-with-env-defaults/defaults_development.yaml @@ -1,3 +1,3 @@ kubernetes-app: - name: "${component_type}-development" + name: ${component_type}-development namespace: development-namespace