ci: Add unit and integration tests
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
"""Shared fixtures for integration tests.
|
||||
|
||||
All integration tests share a single container (session scope) to avoid the
|
||||
overhead of starting/stopping Docker for every test function. Each test that
|
||||
needs filesystem isolation gets its own temporary working directory via the
|
||||
``workdir`` fixture, which is torn down after the test.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import uuid
|
||||
|
||||
import pytest
|
||||
|
||||
from docker_agent_sandbox import DockerSandbox
|
||||
|
||||
# python:3.11-slim ships bash, grep (GNU), find, and standard POSIX utilities.
|
||||
_IMAGE = "python:3.11-slim"
|
||||
_CONTAINER_NAME = "docker-agent-sandbox-tests"
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def sandbox():
|
||||
"""Start a long-running container shared by all integration tests."""
|
||||
sb = DockerSandbox(
|
||||
container_name=_CONTAINER_NAME,
|
||||
image=_IMAGE,
|
||||
command="sleep infinity",
|
||||
cpu_limit=2,
|
||||
memory_limit="512m",
|
||||
)
|
||||
sb.start()
|
||||
yield sb
|
||||
sb.stop()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def workdir(sandbox: DockerSandbox):
|
||||
"""Create a fresh temp directory in the container for the calling test."""
|
||||
d = f"/tmp/test-{uuid.uuid4().hex}"
|
||||
sandbox.exec(f"mkdir -p {d}")
|
||||
yield d
|
||||
sandbox.exec(f"rm -rf {d}")
|
||||
Reference in New Issue
Block a user