Skip to content
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

Run integration tests in GitHub Actions #38

Merged
merged 3 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ jobs:
- run: zig build test --summary all
- run: zig build

- uses: actions/setup-python@v5
with:
python-version: '3.13'
cache: 'pip'

- run: pip install -r tests/requirements.txt
- run: pytest -v tests/

- name: Log in to the Container registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
Expand Down
38 changes: 36 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,42 @@
import requests
import pytest
import subprocess
import socket
from urllib.parse import urljoin


@pytest.fixture(scope='session')
def server_port():
sock = socket.socket()
sock.bind(('', 0))
return sock.getsockname()[1]


@pytest.fixture(scope='session')
def server(server_port, tmp_path_factory):
tmp_dir = tmp_path_factory.mktemp("server")
data_dir = tmp_dir / 'data'
stderr = tmp_dir / 'server.stderr.log'
command = [
'zig-out/bin/fpindex',
'--dir', str(data_dir),
'--port', str(server_port),
'--log-level', 'debug',
]
process = subprocess.Popen(
command,
stdin=subprocess.DEVNULL,
stdout=subprocess.DEVNULL,
stderr=stderr.open('w'),
)
yield
process.terminate()
retcode = process.wait()
if retcode != 0:
for line in stderr.read_text().splitlines():
print(line)


@pytest.fixture
def index_name():
return 'testidx'
Expand Down Expand Up @@ -36,8 +70,8 @@ def session():


@pytest.fixture
def client(session):
return Client(session, 'http://localhost:8080')
def client(session, server_port, server):
return Client(session, f'http://localhost:{server_port}')


@pytest.fixture(autouse=True)
Expand Down
2 changes: 2 additions & 0 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pytest
requests