Skip to content

Commit

Permalink
add e2e pytest setup
Browse files Browse the repository at this point in the history
  • Loading branch information
varshith257 committed Oct 11, 2024
1 parent 1f175b6 commit fe5d93a
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
19 changes: 19 additions & 0 deletions e2e_tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import pytest
import subprocess
import time
import os

@pytest.fixture(scope="session", autouse=True)
def docker_compose_setup():
"""Spin up Docker containers for OPAL services using docker-compose."""
compose_file = os.path.abspath("./docker-compose.yml")

subprocess.run(["docker-compose", "-f", compose_file, "up", "-d"])

# Wait for services to be up and running
time.sleep(60)

yield

# Tear down the Docker services after tests
subprocess.run(["docker-compose", "-f", compose_file, "down"])
20 changes: 20 additions & 0 deletions e2e_tests/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
services:
opal_server:
image: permitio/opal-server:${OPAL_IMAGE_TAG:-latest}
ports:
- "7002:7002"
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:7002/health"]
interval: 10s
timeout: 10s
retries: 5

opal_client:
image: permitio/opal-client:${OPAL_IMAGE_TAG:-latest}
ports:
- "7776:7000"
healthcheck:
test: ["CMD", "curl", "-f", "http://opal_server:7002/health"]
interval: 10s
timeout: 10s
retries: 5
3 changes: 3 additions & 0 deletions e2e_tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pytest
requests
docker
12 changes: 12 additions & 0 deletions e2e_tests/tests/test_e2e.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import requests

def test_opal_server_health():
"""Test OPAL Server health endpoint."""
response = requests.get("http://localhost:7002/policy-data")
assert response.status_code == 200

def test_opal_client_health():
"""Test OPAL Client endpoint."""
response = requests.get("http://localhost:7766/ready")
assert response.status_code == 200
assert 'connected' in response.json()

0 comments on commit fe5d93a

Please sign in to comment.