-
Notifications
You must be signed in to change notification settings - Fork 0
test: add coverage, integration tests, and CI pipeline #3
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| name: CI | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| pull_request: | ||
| branches: [main] | ||
|
|
||
| jobs: | ||
| lint: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 | ||
| - uses: astral-sh/setup-uv@e58605a9b6da7c637471fab8847a5e5a6b8df081 # v5 | ||
| with: | ||
| python-version: "3.11" | ||
| - run: uv sync --extra dev | ||
| - run: uv run ruff check ahab.py tests/ | ||
| - run: uv run ruff format --check ahab.py tests/ | ||
|
|
||
| unit-tests: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 | ||
| - uses: astral-sh/setup-uv@e58605a9b6da7c637471fab8847a5e5a6b8df081 # v5 | ||
| with: | ||
| python-version: "3.11" | ||
| - run: uv sync --extra dev | ||
| - run: uv run pytest --cov --cov-report=term-missing --cov-report=xml -q | ||
| - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4 | ||
| if: always() | ||
| with: | ||
| name: coverage-report | ||
| path: coverage.xml | ||
|
|
||
| integration-tests: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 | ||
| - uses: astral-sh/setup-uv@e58605a9b6da7c637471fab8847a5e5a6b8df081 # v5 | ||
| with: | ||
| python-version: "3.11" | ||
| - run: uv sync --extra dev | ||
| - run: docker compose -f docker-compose.test.yml up -d --wait | ||
| - run: docker compose -f docker-compose.test.yml exec -T dind docker pull alpine:latest | ||
| - run: uv run pytest -m integration -q | ||
| - run: docker compose -f docker-compose.test.yml down -v | ||
| if: always() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,3 +6,6 @@ __pycache__/ | |
| *.egg-info/ | ||
| dist/ | ||
| build/ | ||
| htmlcov/ | ||
| .coverage | ||
| coverage.xml | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| services: | ||
| dind: | ||
| image: docker:27-dind | ||
| privileged: true | ||
| environment: | ||
| DOCKER_TLS_CERTDIR: "" | ||
| ports: | ||
| - "2375:2375" | ||
| healthcheck: | ||
| test: ["CMD", "docker", "info"] | ||
| interval: 5s | ||
| timeout: 3s | ||
| retries: 10 | ||
| tmpfs: | ||
| - /var/lib/docker | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| """Shared fixtures and automatic test markers for ahab test suite.""" | ||
|
|
||
| from unittest.mock import MagicMock | ||
|
|
||
| import pytest | ||
| import requests | ||
|
|
||
| from ahab import DockerAPI | ||
|
|
||
|
|
||
| def pytest_collection_modifyitems(items: list[pytest.Item]) -> None: | ||
| """Auto-apply 'unit' or 'integration' markers based on file location.""" | ||
| for item in items: | ||
| if "test_integration" in str(item.fspath): | ||
| item.add_marker(pytest.mark.integration) | ||
| elif not any(item.iter_markers(name="integration")): | ||
| item.add_marker(pytest.mark.unit) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def mock_api(): | ||
| """A fully-mocked DockerAPI instance (no real HTTP).""" | ||
| return MagicMock(spec=DockerAPI) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def docker_api_with_mock_session(): | ||
| """A real DockerAPI with its session replaced by a mock. | ||
|
|
||
| Use this to test method-level branch logic (status codes, JSON parsing) | ||
| without making real HTTP requests. | ||
| """ | ||
| api = DockerAPI("http://10.0.0.1:2375") | ||
| api.session = MagicMock(spec=requests.Session) | ||
| return api |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Docker daemon port is published as
2375:2375, which binds on all host interfaces by default. Since this is an unauthenticated Docker Remote API endpoint, it should be bound to localhost only (or avoided entirely) to prevent exposing a root-equivalent control socket to the LAN/Wi‑Fi network.