Team Ai
Apppublic

jester1177/cloudnative-devops-debug-env

sourceHugging Faceupdated 6mo agoView on Hugging Face
0likes
test_simulators.py51 linesDownload Raw Back to tests
1from server.models import FileContent, FileType2from server.simulators.docker_simulator import DockerSimulator3from server.simulators.workflow_simulator import WorkflowSimulator4 5 6def _fc(path: str, content: str, file_type: FileType = FileType.OTHER) -> FileContent:7    return FileContent(path=path, content=content, file_type=file_type, line_count=content.count("\n") + 1)8 9 10def test_docker_simulator_catches_missing_copy_source():11    sim = DockerSimulator()12    dockerfile = _fc("Dockerfile", "FROM python:3.11-slim\nCOPY missing.txt .", FileType.DOCKERFILE)13    result = sim.validate(dockerfile, {"Dockerfile": dockerfile})14    assert result["build_success"] is False15    assert "missing.txt" in result.get("error", "")16 17 18def test_docker_simulator_detects_runtime_workdir_issue():19    sim = DockerSimulator()20    dockerfile = _fc(21        "Dockerfile",22        "FROM node:18-alpine\nCOPY package*.json ./\nRUN npm ci\nCOPY . .\nCMD [\"npm\", \"start\"]",23        FileType.DOCKERFILE,24    )25    context = {26        "Dockerfile": dockerfile,27        "package.json": _fc("package.json", '{"name":"app"}'),28    }29    result = sim.validate(dockerfile, context)30    assert result["build_success"] is True31    assert result["run_success"] is False32 33 34def test_workflow_simulator_catches_missing_secrets():35    sim = WorkflowSimulator()36    wf = _fc(37        ".github/workflows/build.yml",38        "name: Build\non: push\njobs:\n  build:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions/checkout@v4\n      - run: echo $DOCKER_PASSWORD | docker login -u $DOCKER_USERNAME --password-stdin",39        FileType.WORKFLOW,40    )41    result = sim.validate(wf, {".github/workflows/build.yml": wf})42    assert result["parse_success"] is True43    assert result["execution_success"] is False44 45 46def test_workflow_simulator_catches_yaml_errors():47    sim = WorkflowSimulator()48    wf = _fc(".github/workflows/build.yml", "jobs:\n  build: [", FileType.WORKFLOW)49    result = sim.validate(wf, {".github/workflows/build.yml": wf})50    assert result["parse_success"] is False51