-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Output interactive mode env to a file (#520)
* Output interactive mode env to a file * Add interactive mode integration test * Add Actions workflow for integration tests
- Loading branch information
Showing
25 changed files
with
180 additions
and
24 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
name: Integration tests | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
integration-test: | ||
name: Run integration tests | ||
runs-on: goth | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Configure python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.8.0' | ||
|
||
- name: Configure poetry | ||
uses: Gr1N/setup-poetry@v4 | ||
with: | ||
poetry-version: 1.1.4 | ||
|
||
- name: Install dependencies | ||
run: poetry install | ||
|
||
- name: Disconnect Docker containers from default network | ||
continue-on-error: true | ||
# related to this issue: https://github.com/moby/moby/issues/23302 | ||
run: | | ||
docker network inspect docker_default | ||
sudo apt-get install -y jq | ||
docker network inspect docker_default | jq ".[0].Containers | map(.Name)[]" | tee /dev/stderr | xargs --max-args 1 -- docker network disconnect -f docker_default | ||
- name: Remove Docker containers | ||
continue-on-error: true | ||
run: docker rm -f $(docker ps -a -q) | ||
|
||
- name: Restart Docker daemon | ||
# related to this issue: https://github.com/moby/moby/issues/23302 | ||
run: sudo systemctl restart docker | ||
|
||
- name: Log in to GitHub Docker repository | ||
run: echo ${{ secrets.GITHUB_TOKEN }} | docker login docker.pkg.github.com -u ${{github.actor}} --password-stdin | ||
|
||
- name: Run unit tests | ||
env: | ||
GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: poetry run poe integration_test | ||
|
||
- name: Upload test logs | ||
uses: actions/upload-artifact@v2 | ||
if: always() | ||
with: | ||
name: goth-logs | ||
path: /tmp/goth-tests | ||
|
||
# Only relevant for self-hosted runners | ||
- name: Remove test logs | ||
if: always() | ||
run: rm -rf /tmp/goth-tests | ||
|
||
# Only relevant for self-hosted runners | ||
- name: Remove poetry virtual env | ||
if: always() | ||
# Python version below should agree with the version set up by this job. | ||
# In future we'll be able to use the `--all` flag here to remove envs for | ||
# all Python versions (https://github.com/python-poetry/poetry/issues/3208). | ||
run: poetry env remove python3.8 | ||
|
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
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
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,23 @@ | ||
"""Fixtures providing common values for integration tests.""" | ||
|
||
from datetime import datetime, timezone | ||
from pathlib import Path | ||
import pytest | ||
|
||
from goth.project import PROJECT_ROOT | ||
|
||
|
||
@pytest.fixture | ||
def log_dir() -> Path: | ||
"""Return path to dir where goth test session logs should be placed.""" | ||
base_dir = Path("/", "tmp", "goth-tests") | ||
date_str = datetime.now(tz=timezone.utc).strftime("%Y%m%d_%H%M%S%z") | ||
log_dir = base_dir / f"goth_{date_str}" | ||
log_dir.mkdir(parents=True) | ||
return log_dir | ||
|
||
|
||
@pytest.fixture | ||
def default_goth_config() -> Path: | ||
"""Return path to default `goth-config.yml` file.""" | ||
return PROJECT_ROOT / "goth" / "default-assets" / "goth-config.yml" |
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,34 @@ | ||
"""Integration tests for the goth interactive mode.""" | ||
|
||
import asyncio | ||
from pathlib import Path | ||
import pytest | ||
|
||
from goth.configuration import load_yaml | ||
from goth.interactive import start_network, env_file | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_interactive( | ||
capsys: pytest.CaptureFixture, default_goth_config: Path, log_dir: Path | ||
) -> None: | ||
"""Test if goth interactive mode launches correctly.""" | ||
goth_config = load_yaml(default_goth_config, []) | ||
interactive_task = asyncio.create_task(start_network(goth_config, log_dir)) | ||
|
||
async def _scan_stdout(): | ||
expected_msg = "Local goth network ready" | ||
while True: | ||
stdout, _stderr = capsys.readouterr() | ||
if expected_msg in stdout: | ||
break | ||
await asyncio.sleep(0.1) | ||
|
||
try: | ||
await asyncio.wait_for(_scan_stdout(), timeout=90) | ||
assert env_file.exists() | ||
except asyncio.TimeoutError: | ||
pytest.fail("Timeout while waiting for interactive mode to start") | ||
finally: | ||
interactive_task.cancel() | ||
await interactive_task |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.