|
3 | 3 | """ |
4 | 4 |
|
5 | 5 | import pytest |
| 6 | +import testinfra |
| 7 | +import testinfra.host |
6 | 8 |
|
7 | 9 |
|
8 | 10 | @pytest.mark.end_to_end |
9 | 11 | @pytest.mark.end_to_end_docker |
10 | 12 | def test_int_docker_install_package_ubuntu(helpers): |
11 | | - helpers.run_check_output( |
12 | | - "pyinfra -y --chdir examples @docker/ubuntu:22.04 apt.packages iftop update=true", |
13 | | - expected_lines=["docker build complete"], |
| 13 | + def check(host: testinfra.host.Host): |
| 14 | + assert host.package("iftop").is_installed |
| 15 | + |
| 16 | + helpers.run_container_test_host( |
| 17 | + "ubuntu:22.04", |
| 18 | + "apt.packages packages=iftop update=true", |
| 19 | + check, |
| 20 | + ) |
| 21 | + |
| 22 | + |
| 23 | +@pytest.mark.end_to_end |
| 24 | +@pytest.mark.end_to_end_docker |
| 25 | +def test_int_docker_file(helpers): |
| 26 | + def check(host: testinfra.host.Host): |
| 27 | + file = host.file("/testfile") |
| 28 | + assert file.is_file |
| 29 | + assert file.user == "nobody" |
| 30 | + assert file.group == "root" |
| 31 | + assert file.mode == 0o755 |
| 32 | + |
| 33 | + helpers.run_container_test_host( |
| 34 | + "ubuntu:22.04", |
| 35 | + "files.file path=/testfile mode=755 user=nobody", |
| 36 | + check, |
14 | 37 | ) |
15 | 38 |
|
16 | 39 |
|
17 | 40 | @pytest.mark.end_to_end |
18 | 41 | @pytest.mark.end_to_end_docker |
19 | | -def test_int_podman_install_package_ubuntu(helpers): |
20 | | - helpers.run_check_output( |
21 | | - "pyinfra -y --chdir examples @podman/ubuntu:22.04 apt.packages iftop update=true", |
22 | | - expected_lines=["podman build complete"], |
| 42 | +def test_int_docker_put_file(helpers): |
| 43 | + # TODO: why does importing this at top level break things? |
| 44 | + from pyinfra.api.util import get_file_sha256 |
| 45 | + |
| 46 | + with open("README.md", "r") as f: |
| 47 | + expected_sum = get_file_sha256(f) |
| 48 | + |
| 49 | + def check(host: testinfra.host.Host): |
| 50 | + file = host.file("/README.md") |
| 51 | + assert file.is_file |
| 52 | + assert file.sha256sum == expected_sum |
| 53 | + |
| 54 | + helpers.run_container_test_host( |
| 55 | + "ubuntu:22.04", |
| 56 | + "files.put src=README.md dest=README.md mode=755 user=nobody", |
| 57 | + check, |
23 | 58 | ) |
0 commit comments