diff --git a/goth/interactive.py b/goth/interactive.py index 4e598d661..9764b1d57 100644 --- a/goth/interactive.py +++ b/goth/interactive.py @@ -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: diff --git a/pyproject.toml b/pyproject.toml index 679ad56db..48583bc2b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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"] diff --git a/test/integration/conftest.py b/test/integration/conftest.py new file mode 100644 index 000000000..9ac3299fd --- /dev/null +++ b/test/integration/conftest.py @@ -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" diff --git a/test/integration/test_interactive.py b/test/integration/test_interactive.py new file mode 100644 index 000000000..ba80fbb64 --- /dev/null +++ b/test/integration/test_interactive.py @@ -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 diff --git a/test/goth/assertions/test_assertions.py b/test/unit/assertions/test_assertions.py similarity index 100% rename from test/goth/assertions/test_assertions.py rename to test/unit/assertions/test_assertions.py diff --git a/test/goth/assertions/test_monitor.py b/test/unit/assertions/test_monitor.py similarity index 100% rename from test/goth/assertions/test_monitor.py rename to test/unit/assertions/test_monitor.py diff --git a/test/goth/configuration/test-assets/goth-config.yml b/test/unit/configuration/test-assets/goth-config.yml similarity index 100% rename from test/goth/configuration/test-assets/goth-config.yml rename to test/unit/configuration/test-assets/goth-config.yml diff --git a/test/goth/configuration/test-assets/keys/001.json b/test/unit/configuration/test-assets/keys/001.json similarity index 100% rename from test/goth/configuration/test-assets/keys/001.json rename to test/unit/configuration/test-assets/keys/001.json diff --git a/test/goth/configuration/test_configuration.py b/test/unit/configuration/test_configuration.py similarity index 100% rename from test/goth/configuration/test_configuration.py rename to test/unit/configuration/test_configuration.py diff --git a/test/goth/runner/cli/__init__.py b/test/unit/runner/cli/__init__.py similarity index 100% rename from test/goth/runner/cli/__init__.py rename to test/unit/runner/cli/__init__.py diff --git a/test/goth/runner/cli/conftest.py b/test/unit/runner/cli/conftest.py similarity index 100% rename from test/goth/runner/cli/conftest.py rename to test/unit/runner/cli/conftest.py diff --git a/test/goth/runner/cli/mock.py b/test/unit/runner/cli/mock.py similarity index 100% rename from test/goth/runner/cli/mock.py rename to test/unit/runner/cli/mock.py diff --git a/test/goth/runner/cli/test_command_runner.py b/test/unit/runner/cli/test_command_runner.py similarity index 100% rename from test/goth/runner/cli/test_command_runner.py rename to test/unit/runner/cli/test_command_runner.py diff --git a/test/goth/runner/cli/test_yagna_app_key_cmd.py b/test/unit/runner/cli/test_yagna_app_key_cmd.py similarity index 100% rename from test/goth/runner/cli/test_yagna_app_key_cmd.py rename to test/unit/runner/cli/test_yagna_app_key_cmd.py diff --git a/test/goth/runner/cli/test_yagna_id_cmd.py b/test/unit/runner/cli/test_yagna_id_cmd.py similarity index 100% rename from test/goth/runner/cli/test_yagna_id_cmd.py rename to test/unit/runner/cli/test_yagna_id_cmd.py diff --git a/test/goth/runner/cli/test_yagna_payment_cmd.py b/test/unit/runner/cli/test_yagna_payment_cmd.py similarity index 100% rename from test/goth/runner/cli/test_yagna_payment_cmd.py rename to test/unit/runner/cli/test_yagna_payment_cmd.py diff --git a/test/goth/runner/container/test_container.py b/test/unit/runner/container/test_container.py similarity index 100% rename from test/goth/runner/container/test_container.py rename to test/unit/runner/container/test_container.py diff --git a/test/goth/runner/container/test_payment.py b/test/unit/runner/container/test_payment.py similarity index 100% rename from test/goth/runner/container/test_payment.py rename to test/unit/runner/container/test_payment.py diff --git a/test/goth/runner/container/test_utils.py b/test/unit/runner/container/test_utils.py similarity index 100% rename from test/goth/runner/container/test_utils.py rename to test/unit/runner/container/test_utils.py diff --git a/test/goth/runner/probe/test_run_command_on_host.py b/test/unit/runner/probe/test_run_command_on_host.py similarity index 100% rename from test/goth/runner/probe/test_run_command_on_host.py rename to test/unit/runner/probe/test_run_command_on_host.py diff --git a/test/goth/runner/test_assertion_monitors.py b/test/unit/runner/test_assertion_monitors.py similarity index 100% rename from test/goth/runner/test_assertion_monitors.py rename to test/unit/runner/test_assertion_monitors.py diff --git a/test/goth/runner/test_shutdown.py b/test/unit/runner/test_shutdown.py similarity index 100% rename from test/goth/runner/test_shutdown.py rename to test/unit/runner/test_shutdown.py