Skip to content

tests/integration: add integration test for an operator like environment #294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 28, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion tests/integration/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import os.path

import pytest

from .utils import ElasticIntegrationTestCase, OTEL_INSTRUMENTATION_VERSION
from .utils import ElasticIntegrationTestCase, OTEL_INSTRUMENTATION_VERSION, ROOT_DIR


@pytest.mark.integration
Expand Down Expand Up @@ -139,3 +141,37 @@ def send_event():
(log,) = telemetry["logs"]
self.assertEqual(log["attributes"]["event.name"], "test.event")
self.assertEqual(log["body"], {"key": "value", "dict": {"nestedkey": "nestedvalue"}})


@pytest.mark.integration
class OperatorTestCase(ElasticIntegrationTestCase):
@staticmethod
def _read_operator_requirements():
requirements = []
with open(os.path.join(ROOT_DIR, "operator", "requirements.txt")) as reqf:
for line in reqf:
req = line.strip()
if req:
requirements.append(req)
return requirements

@classmethod
def requirements(cls):
requirements = super().requirements()
return requirements + cls._read_operator_requirements()

def script(self):
import sqlite3

connection = sqlite3.connect(":memory:")
cursor = connection.cursor()
cursor.execute("CREATE TABLE movie(title, year, score)")

def test_auto_instrumentation_works(self):
stdout, stderr, returncode = self.run_script(self.script, wrapper_script="opentelemetry-instrument")

telemetry = self.get_telemetry()
(span,) = telemetry["traces"]
self.assertTrue(span)

self.assertEqual(returncode, 0)