Skip to content

Commit 07760e3

Browse files
Add unit tests
1 parent 75a23d5 commit 07760e3

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

instrumentation/opentelemetry-instrumentation-mysql/tests/test_mysql_integration.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,42 @@ def test_instrument_connection_no_op_tracer_provider(self, mock_connect):
102102
spans_list = self.memory_exporter.get_finished_spans()
103103
self.assertEqual(len(spans_list), 0)
104104

105+
@mock.patch("opentelemetry.instrumentation.dbapi.instrument_connection")
106+
@mock.patch("mysql.connector.connect")
107+
# pylint: disable=unused-argument
108+
def test_instrument_connection_enable_commenter(
109+
self,
110+
mock_connect,
111+
mock_instrument_connection,
112+
):
113+
cnx, query = connect_and_execute_query()
114+
cnx = MySQLInstrumentor().instrument_connection(
115+
cnx,
116+
enable_commenter=True,
117+
commenter_options={"foo": True},
118+
)
119+
cursor = cnx.cursor()
120+
cursor.execute(query)
121+
kwargs = mock_instrument_connection.call_args[1]
122+
self.assertEqual(kwargs["enable_commenter"], True)
123+
self.assertEqual(kwargs["commenter_options"], {"foo": True})
124+
125+
@mock.patch("opentelemetry.instrumentation.dbapi.wrap_connect")
126+
@mock.patch("mysql.connector.connect")
127+
# pylint: disable=unused-argument
128+
def test__instrument_enable_commenter(
129+
self,
130+
mock_connect,
131+
mock_wrap_connect,
132+
):
133+
MySQLInstrumentor()._instrument(
134+
enable_commenter=True,
135+
commenter_options={"foo": True},
136+
)
137+
kwargs = mock_wrap_connect.call_args[1]
138+
self.assertEqual(kwargs["enable_commenter"], True)
139+
self.assertEqual(kwargs["commenter_options"], {"foo": True})
140+
105141
@mock.patch("mysql.connector.connect")
106142
# pylint: disable=unused-argument
107143
def test_uninstrument_connection(self, mock_connect):

0 commit comments

Comments
 (0)