Skip to content

Commit

Permalink
Add interactive mode integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
kmazurek committed Jul 27, 2021
1 parent 9aa40c3 commit 22ae9d1
Show file tree
Hide file tree
Showing 22 changed files with 60 additions and 2 deletions.
2 changes: 1 addition & 1 deletion goth/interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

logger = logging.getLogger(__name__)

env_file = Path(tempfile.gettempdir()) / "goth_interactive.env"
env_file: Path = Path(tempfile.gettempdir()) / "goth_interactive.env"


def _write_env_file(env: Dict[str, str]) -> None:
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ pytest = "^6.2"
codeformat = "black -v --check --diff ."
codestyle = "flake8"
interactive = "python -m goth start goth/default-assets/goth-config.yml"
unit_test = "pytest -svx test/goth"
unit_test = "pytest -svx test/unit"
integration_test = "pytest -svx test/integration"

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand Down
23 changes: 23 additions & 0 deletions test/integration/conftest.py
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"
34 changes: 34 additions & 0 deletions test/integration/test_interactive.py
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.

0 comments on commit 22ae9d1

Please sign in to comment.