Skip to content

Commit

Permalink
Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tammy-baylis-swi committed Oct 17, 2024
1 parent 75a23d5 commit 07760e3
Showing 1 changed file with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,42 @@ def test_instrument_connection_no_op_tracer_provider(self, mock_connect):
spans_list = self.memory_exporter.get_finished_spans()
self.assertEqual(len(spans_list), 0)

@mock.patch("opentelemetry.instrumentation.dbapi.instrument_connection")
@mock.patch("mysql.connector.connect")
# pylint: disable=unused-argument
def test_instrument_connection_enable_commenter(
self,
mock_connect,
mock_instrument_connection,
):
cnx, query = connect_and_execute_query()
cnx = MySQLInstrumentor().instrument_connection(
cnx,
enable_commenter=True,
commenter_options={"foo": True},
)
cursor = cnx.cursor()
cursor.execute(query)
kwargs = mock_instrument_connection.call_args[1]
self.assertEqual(kwargs["enable_commenter"], True)
self.assertEqual(kwargs["commenter_options"], {"foo": True})

@mock.patch("opentelemetry.instrumentation.dbapi.wrap_connect")
@mock.patch("mysql.connector.connect")
# pylint: disable=unused-argument
def test__instrument_enable_commenter(
self,
mock_connect,
mock_wrap_connect,
):
MySQLInstrumentor()._instrument(
enable_commenter=True,
commenter_options={"foo": True},
)
kwargs = mock_wrap_connect.call_args[1]
self.assertEqual(kwargs["enable_commenter"], True)
self.assertEqual(kwargs["commenter_options"], {"foo": True})

@mock.patch("mysql.connector.connect")
# pylint: disable=unused-argument
def test_uninstrument_connection(self, mock_connect):
Expand Down

0 comments on commit 07760e3

Please sign in to comment.