-
Notifications
You must be signed in to change notification settings - Fork 9
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
feat: add examples folder #48
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
2ab5770
feat: add examples folder
dbluhm f54141e
refactor: use example.py naming convention instead dunder main
dbluhm 294e9d1
feat: update presentation revoked creds example
dbluhm 15a33d3
feat: test examples
dbluhm 15e6b4c
refactor: move tunnels example
dbluhm 68d5f72
fix: final fix for root example
dbluhm f20dd5f
chore: remove minimal example at root
dbluhm 56c132f
fix: reference to removed file
dbluhm aece501
ci: only run on PRs to main
dbluhm 7f2e7e8
refactor: remove configs
dbluhm 305f7c7
chore: remove unused method
dbluhm 11a8a70
fix: add webhook listener back ing
dbluhm 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 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 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 |
---|---|---|
@@ -1,26 +1,42 @@ | ||
# Authored by Alexandra N. Walker <[email protected]> ☀️ | ||
|
||
name: tests | ||
name: Tests | ||
"on": | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
- feature/** | ||
- feat/** | ||
|
||
env: | ||
POETRY_VERSION: 1.1.11 | ||
POETRY_VERSION: 1.5.1 | ||
|
||
jobs: | ||
test: | ||
name: Tests | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Test with docker-compose | ||
- uses: actions/checkout@v3 | ||
- name: Run integration tests for protocols | ||
run: | | ||
docker-compose run tests | ||
docker-compose run tests tests/ | ||
|
||
examples: | ||
name: Check examples | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Install poetry | ||
run: pipx install poetry==${{ env.POETRY_VERSION}} | ||
- name: setup python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: 3.9 | ||
cache: poetry | ||
- name: Install dependencies | ||
run: poetry install | ||
- name: Run examples | ||
run: | | ||
poetry run pytest -m examples |
This file contains 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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,120 @@ | ||
from pathlib import Path | ||
import subprocess | ||
from typing import Union | ||
|
||
from py._path.local import LocalPath | ||
import pytest | ||
from pytest import Session | ||
|
||
|
||
EXAMPLES_DIR = Path(__file__).parent / "examples" | ||
|
||
|
||
class ExampleFailedException(Exception): | ||
"""Raised when an example fails.""" | ||
|
||
def __init__(self, message: str, exit_status: int): | ||
super().__init__(message) | ||
self.exit_status = exit_status | ||
|
||
|
||
class ExampleRunner: | ||
"""Run the docker-compose of a given example.""" | ||
|
||
def __init__(self, compose_file: str): | ||
self.compose_file = compose_file | ||
|
||
def compose(self, *command: str) -> int: | ||
"""Runs docker-compose using subprocess with the given command. | ||
|
||
Returns exit status and output. | ||
""" | ||
try: | ||
subprocess.run( | ||
["docker-compose", "-f", self.compose_file, *command], | ||
check=True, | ||
) | ||
return 0 | ||
except subprocess.CalledProcessError as e: | ||
return e.returncode | ||
|
||
def cleanup(self): | ||
"""Runs docker-compose down -v for cleanup""" | ||
exit_status = self.compose("down", "-v") | ||
if exit_status != 0: | ||
raise ExampleFailedException( | ||
f"Cleanup failed with exit status {exit_status}", exit_status | ||
) | ||
|
||
def handle_run(self, *command: str): | ||
"""Handles the run of docker-compose/ | ||
|
||
raises exception if exit status is non-zero. | ||
""" | ||
try: | ||
exit_status = self.compose(*command) | ||
if exit_status != 0: | ||
raise ExampleFailedException( | ||
f"Command failed with exit status: {exit_status}", | ||
exit_status=exit_status, | ||
) | ||
finally: | ||
self.cleanup() | ||
|
||
|
||
def pytest_collect_file(parent: Session, path: Union[LocalPath, Path]): | ||
"""Pytest collection hook. | ||
|
||
This will collect the docker-compose.yml files from the examples and create | ||
pytest items to run them. | ||
""" | ||
file = Path(str(path)) | ||
|
||
# Skip certain examples | ||
if (file.parent / "__skip__").exists(): | ||
return | ||
|
||
if file.suffix == ".yml" and file.parent.parent == EXAMPLES_DIR: | ||
return ExampleFile.from_parent(parent, path=file.parent) | ||
|
||
|
||
class ExampleFile(pytest.File): | ||
"""Pytest file for example.""" | ||
|
||
def collect(self): | ||
"""Collect tests from example file.""" | ||
path = Path(self.fspath) | ||
item = ExmapleItem.from_parent( | ||
self, name=path.name, compose_file=str(path / "docker-compose.yml") | ||
) | ||
item.add_marker(pytest.mark.examples) | ||
yield item | ||
|
||
|
||
class ExmapleItem(pytest.Item): | ||
"""Example item. | ||
|
||
Runs the docker-compose.yml file of the example and reports failure if the | ||
exit status is non-zero. | ||
""" | ||
|
||
def __init__(self, name: str, parent: pytest.File, compose_file: str): | ||
super().__init__(name, parent) | ||
self.compose_file = compose_file | ||
|
||
def runtest(self) -> None: | ||
ExampleRunner(self.compose_file).handle_run("run", "example") | ||
|
||
def repr_failure(self, excinfo): | ||
"""Called when self.runtest() raises an exception.""" | ||
if isinstance(excinfo.value, ExampleFailedException): | ||
return "\n".join( | ||
[ | ||
"Example failed!", | ||
f" {excinfo.value}", | ||
] | ||
) | ||
return f"Some other exectpion happened: {excinfo.value}" | ||
|
||
def reportinfo(self): | ||
return self.fspath, 0, f"example: {self.name}" |
This file contains 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
Oops, something went wrong.
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.
on my m1 system, I run
docker compose
notdocker-compose
on the command line.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.
Ah, right. Fun lol. I'll try to figure out if there's a straightforward way to account for that.
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.
https://docs.docker.com/compose/migrate/#docker-compose-vs-docker-compose
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.
Maybe a silly comment along these lines, @dbluhm wasn't this mentioned during the ACA-Pug meeting today? Might be able to be reconciled in the future (very possible I'm off on this)
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.
I'm thinking it might be simplest to just alias
docker-compose
fordocker compose
locally if you want to run these directly. Else, we can always just let the action run it and not worry about local environments.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.
Not sure I heard mention of docker-compose vs docker compose on the ACA-PUG call today 🤔
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.
Ah, no wait you're right, I was confusing it with the amd vs. arm thingy/separate thing, my bad