Skip to content

Commit

Permalink
add setter/getter
Browse files Browse the repository at this point in the history
  • Loading branch information
dimastbk committed Aug 31, 2024
1 parent f165624 commit 28cd78f
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
from unittest import IsolatedAsyncioTestCase, mock

from opentelemetry.instrumentation.aiokafka.utils import (
AIOKafkaContextGetter,
AIOKafkaContextSetter,
AIOKafkaPropertiesExtractor,
_aiokafka_getter,
_aiokafka_setter,
Expand All @@ -35,6 +37,22 @@ def setUp(self) -> None:
self.headers = []
self.kwargs = {"partition": 0, "headers": self.headers}

def test_context_setter(self) -> None:
context_setter = AIOKafkaContextSetter()

carrier_list = [("key1", b"val1")]
context_setter.set(carrier_list, "key2", "val2")
self.assertTrue(("key2", "val2".encode()) in carrier_list)

def test_context_getter(self) -> None:
context_setter = AIOKafkaContextSetter()
context_getter = AIOKafkaContextGetter()

carrier_list = []
context_setter.set(carrier_list, "key1", "val1")
self.assertEqual(context_getter.get(carrier_list, "key1"), ["val1"])
self.assertEqual(["key1"], context_getter.keys(carrier_list))

@mock.patch(
"opentelemetry.instrumentation.aiokafka.utils.AIOKafkaPropertiesExtractor.extract_bootstrap_servers"
)
Expand Down

0 comments on commit 28cd78f

Please sign in to comment.