Download tests/test_simulators.py from jester1177/cloudnative-devops-debug-env: direct link, hf CLI and curl.
- Browser
- Download file 2.07 kB
-
https://huggingface.co/spaces/jester1177/cloudnative-devops-debug-env/resolve/main/tests/test_simulators.py
- Command line
-
hf download hf://spaces/jester1177/cloudnative-devops-debug-env/tests/test_simulators.py
-
curl -L -o test_simulators.py https://huggingface.co/spaces/jester1177/cloudnative-devops-debug-env/resolve/main/tests/test_simulators.py
2.07 kB
| from server.models import FileContent, FileType | |
| from server.simulators.docker_simulator import DockerSimulator | |
| from server.simulators.workflow_simulator import WorkflowSimulator | |
| def _fc(path: str, content: str, file_type: FileType = FileType.OTHER) -> FileContent: | |
| return FileContent(path=path, content=content, file_type=file_type, line_count=content.count("\n") + 1) | |
| def test_docker_simulator_catches_missing_copy_source(): | |
| sim = DockerSimulator() | |
| dockerfile = _fc("Dockerfile", "FROM python:3.11-slim\nCOPY missing.txt .", FileType.DOCKERFILE) | |
| result = sim.validate(dockerfile, {"Dockerfile": dockerfile}) | |
| assert result["build_success"] is False | |
| assert "missing.txt" in result.get("error", "") | |
| def test_docker_simulator_detects_runtime_workdir_issue(): | |
| sim = DockerSimulator() | |
| dockerfile = _fc( | |
| "Dockerfile", | |
| "FROM node:18-alpine\nCOPY package*.json ./\nRUN npm ci\nCOPY . .\nCMD [\"npm\", \"start\"]", | |
| FileType.DOCKERFILE, | |
| ) | |
| context = { | |
| "Dockerfile": dockerfile, | |
| "package.json": _fc("package.json", '{"name":"app"}'), | |
| } | |
| result = sim.validate(dockerfile, context) | |
| assert result["build_success"] is True | |
| assert result["run_success"] is False | |
| def test_workflow_simulator_catches_missing_secrets(): | |
| sim = WorkflowSimulator() | |
| wf = _fc( | |
| ".github/workflows/build.yml", | |
| "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", | |
| FileType.WORKFLOW, | |
| ) | |
| result = sim.validate(wf, {".github/workflows/build.yml": wf}) | |
| assert result["parse_success"] is True | |
| assert result["execution_success"] is False | |
| def test_workflow_simulator_catches_yaml_errors(): | |
| sim = WorkflowSimulator() | |
| wf = _fc(".github/workflows/build.yml", "jobs:\n build: [", FileType.WORKFLOW) | |
| result = sim.validate(wf, {".github/workflows/build.yml": wf}) | |
| assert result["parse_success"] is False | |