From bd87b06a52d532da224b4f5b816f681b03de5438 Mon Sep 17 00:00:00 2001 From: Vamshi Maskuri <117595548+varshith257@users.noreply.github.com> Date: Fri, 11 Oct 2024 14:55:02 +0530 Subject: [PATCH 1/3] add e2e pytest setup --- e2e_tests/conftest.py | 19 +++++++++++++++++++ e2e_tests/docker-compose.yml | 20 ++++++++++++++++++++ e2e_tests/requirements.txt | 3 +++ e2e_tests/tests/test_e2e.py | 12 ++++++++++++ 4 files changed, 54 insertions(+) create mode 100644 e2e_tests/conftest.py create mode 100644 e2e_tests/docker-compose.yml create mode 100644 e2e_tests/requirements.txt create mode 100644 e2e_tests/tests/test_e2e.py diff --git a/e2e_tests/conftest.py b/e2e_tests/conftest.py new file mode 100644 index 000000000..12b975e24 --- /dev/null +++ b/e2e_tests/conftest.py @@ -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"]) diff --git a/e2e_tests/docker-compose.yml b/e2e_tests/docker-compose.yml new file mode 100644 index 000000000..ef3dca279 --- /dev/null +++ b/e2e_tests/docker-compose.yml @@ -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 diff --git a/e2e_tests/requirements.txt b/e2e_tests/requirements.txt new file mode 100644 index 000000000..35b47dcaf --- /dev/null +++ b/e2e_tests/requirements.txt @@ -0,0 +1,3 @@ +pytest +requests +docker \ No newline at end of file diff --git a/e2e_tests/tests/test_e2e.py b/e2e_tests/tests/test_e2e.py new file mode 100644 index 000000000..50b205ca9 --- /dev/null +++ b/e2e_tests/tests/test_e2e.py @@ -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() From 5cc1754f742afe2952a97e33999684d12ea009c6 Mon Sep 17 00:00:00 2001 From: Vamshi Maskuri <117595548+varshith257@users.noreply.github.com> Date: Fri, 11 Oct 2024 15:37:24 +0530 Subject: [PATCH 2/3] fix conflicts --- e2e_tests/docker-compose.yml | 8 +++++--- e2e_tests/tests/test_e2e.py | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/e2e_tests/docker-compose.yml b/e2e_tests/docker-compose.yml index ef3dca279..5bc5c4b73 100644 --- a/e2e_tests/docker-compose.yml +++ b/e2e_tests/docker-compose.yml @@ -4,7 +4,7 @@ services: ports: - "7002:7002" healthcheck: - test: ["CMD", "curl", "-f", "http://localhost:7002/health"] + test: ["CMD", "curl", "-f", "http://localhost:7002/healthcheck"] interval: 10s timeout: 10s retries: 5 @@ -12,9 +12,11 @@ services: opal_client: image: permitio/opal-client:${OPAL_IMAGE_TAG:-latest} ports: - - "7776:7000" + - "7000:7000" + depends_on: + - opal_server healthcheck: - test: ["CMD", "curl", "-f", "http://opal_server:7002/health"] + test: ["CMD", "curl", "-f", "http://localhost:7000/healthcheck"] interval: 10s timeout: 10s retries: 5 diff --git a/e2e_tests/tests/test_e2e.py b/e2e_tests/tests/test_e2e.py index 50b205ca9..0cbd27574 100644 --- a/e2e_tests/tests/test_e2e.py +++ b/e2e_tests/tests/test_e2e.py @@ -1,12 +1,14 @@ import requests +import time def test_opal_server_health(): """Test OPAL Server health endpoint.""" - response = requests.get("http://localhost:7002/policy-data") + response = requests.get("http://localhost:7002/healthcheck") assert response.status_code == 200 def test_opal_client_health(): """Test OPAL Client endpoint.""" - response = requests.get("http://localhost:7766/ready") + + response = requests.get("http://localhost:7000/healthcheck") assert response.status_code == 200 - assert 'connected' in response.json() + print(response.json()) \ No newline at end of file From 1c6b3ea594ada73787ac707d4f56c9ebc7f31737 Mon Sep 17 00:00:00 2001 From: Vamshi Maskuri <117595548+varshith257@users.noreply.github.com> Date: Fri, 11 Oct 2024 16:46:00 +0530 Subject: [PATCH 3/3] use exisitng docker-compose file --- e2e_tests/conftest.py | 4 ++-- e2e_tests/docker-compose.yml | 22 ---------------------- e2e_tests/tests/test_e2e.py | 18 ++++++++++++++---- 3 files changed, 16 insertions(+), 28 deletions(-) delete mode 100644 e2e_tests/docker-compose.yml diff --git a/e2e_tests/conftest.py b/e2e_tests/conftest.py index 12b975e24..c554433da 100644 --- a/e2e_tests/conftest.py +++ b/e2e_tests/conftest.py @@ -6,12 +6,12 @@ @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") + compose_file = os.path.abspath("../app-tests/docker-compose-app-tests.yml") subprocess.run(["docker-compose", "-f", compose_file, "up", "-d"]) # Wait for services to be up and running - time.sleep(60) + time.sleep(10) yield diff --git a/e2e_tests/docker-compose.yml b/e2e_tests/docker-compose.yml deleted file mode 100644 index 5bc5c4b73..000000000 --- a/e2e_tests/docker-compose.yml +++ /dev/null @@ -1,22 +0,0 @@ -services: - opal_server: - image: permitio/opal-server:${OPAL_IMAGE_TAG:-latest} - ports: - - "7002:7002" - healthcheck: - test: ["CMD", "curl", "-f", "http://localhost:7002/healthcheck"] - interval: 10s - timeout: 10s - retries: 5 - - opal_client: - image: permitio/opal-client:${OPAL_IMAGE_TAG:-latest} - ports: - - "7000:7000" - depends_on: - - opal_server - healthcheck: - test: ["CMD", "curl", "-f", "http://localhost:7000/healthcheck"] - interval: 10s - timeout: 10s - retries: 5 diff --git a/e2e_tests/tests/test_e2e.py b/e2e_tests/tests/test_e2e.py index 0cbd27574..564b440f0 100644 --- a/e2e_tests/tests/test_e2e.py +++ b/e2e_tests/tests/test_e2e.py @@ -1,14 +1,24 @@ import requests import time +import subprocess + +def check_logs(container_name): + result = subprocess.run(["docker", "logs", container_name], capture_output=True, text=True) + assert "ERROR" not in result.stdout and "CRITICAL" not in result.stdout, f"Critical errors found in {container_name}" def test_opal_server_health(): """Test OPAL Server health endpoint.""" - response = requests.get("http://localhost:7002/healthcheck") + response = requests.get("http://opal_server:7002/healthcheck") assert response.status_code == 200 def test_opal_client_health(): """Test OPAL Client endpoint.""" - - response = requests.get("http://localhost:7000/healthcheck") + response = requests.get("http://opal_client:7000/healthcheck") assert response.status_code == 200 - print(response.json()) \ No newline at end of file + print(response.json()) + +def test_opal_server_logs(): + check_logs("app-tests-opal_server-1") + +def test_opal_client_logs(): + check_logs("app-tests-opal_client-1")