Skip to content

Commit

Permalink
Enhance CI tests for Docker role
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastian Neumann <[email protected]>
  • Loading branch information
sbstnnmnn committed Sep 19, 2024
1 parent 152f3b8 commit e2d125e
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions molecule/delegated/tests/docker/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import pytest

from ..util.util import get_ansible, get_variable, jinja_list_concat
from ..util.util import (
get_ansible,
get_variable,
jinja_list_concat,
)

testinfra_runner, testinfra_hosts = get_ansible()

Expand Down Expand Up @@ -142,7 +146,7 @@ def test_containerd(host):

def test_python(host):
docker_python_install_from_pip = (
get_variable(host, "docker_python_install_from_pip") is True
get_variable(host, "docker_python_install_from_pip") is True
)

docker_python3_package_name = get_variable(host, "docker_python3_package_name")
Expand Down Expand Up @@ -190,3 +194,27 @@ def test_dockerlogin(host):

package = host.package("pass")
assert package.is_installed


@pytest.mark.parametrize(
"name,image,expected_output",
[("docker_test", "docker.io/hello-world:latest", "Hello from Docker!")],
)
def test_docker_installation(host, name, image, expected_output):
# Check Docker version
docker_version = host.run("docker --version")
assert docker_version.rc == 0
assert "docker version" in docker_version.stdout.lower()

# Note: On CentOS, sudo is typically required for Docker commands due to SELinux.

# Run a test container
with host.sudo():
container = host.run(f"docker run --name {name} {image}")
assert container.rc == 0
assert expected_output in container.stdout

# Check if Docker can list images
with host.sudo():
list_images = host.run("docker images")
assert list_images.rc == 0

0 comments on commit e2d125e

Please sign in to comment.