-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
77aab23
commit e0e179a
Showing
4 changed files
with
75 additions
and
5 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
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,22 @@ | ||
from __future__ import annotations | ||
|
||
from pathlib import Path | ||
|
||
from binharness.bootstrap.docker import DockerAgent, bootstrap_env_from_image | ||
from binharness.types.executor import NullExecutor | ||
from binharness.types.target import Target | ||
|
||
|
||
def test_bootstrap_env_from_image(agent_binary_linux_host_arch: str) -> None: | ||
agent = bootstrap_env_from_image(agent_binary_linux_host_arch, "ubuntu:22.04") | ||
|
||
assert isinstance(agent, DockerAgent) | ||
assert agent.get_environment_ids() == [0] | ||
|
||
env = agent.get_environment(0) | ||
target = Target(env, Path("/usr/bin/echo"), args=["hello world"]) | ||
proc = NullExecutor().run_target(target) | ||
|
||
proc.wait() | ||
assert proc.returncode == 0 | ||
assert proc.stdout.read() == b"hello world\n" |
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,14 +1,47 @@ | ||
from __future__ import annotations | ||
|
||
import platform | ||
import sys | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
ALL = {"darwin", "linux", "win32"} | ||
|
||
|
||
def pytest_runtest_setup(item: pytest.Item) -> None: | ||
# Skip tests not marked as supported on the current platform | ||
supported_platforms = ALL.intersection(mark.name for mark in item.iter_markers()) | ||
plat = sys.platform | ||
if supported_platforms and plat not in supported_platforms: | ||
pytest.skip(f"cannot run on platform {plat}") | ||
|
||
# Skip docker tests if docker is not installed | ||
if "docker" in list(item.iter_markers()): | ||
try: | ||
import docker | ||
except ImportError: | ||
pytest.skip("docker is not installed") | ||
try: | ||
docker.from_env() | ||
except docker.errors.DockerException: | ||
pytest.skip("docker is not running") | ||
|
||
|
||
@pytest.fixture() | ||
def agent_binary_linux_host_arch() -> str: | ||
arch = platform.machine() | ||
# Fixup arch for arm64 | ||
if arch == "arm64": | ||
arch = "aarch64" | ||
|
||
expected_path = ( | ||
Path(__file__).parent.parent.parent | ||
/ "target" | ||
/ f"{arch}-unknown-linux-musl" | ||
/ "debug" | ||
/ "bh_agent_server" | ||
).absolute() | ||
if not expected_path.exists(): | ||
pytest.skip("agent binary not found") | ||
return str(expected_path) |