Skip to content

Commit

Permalink
Add more smoke tests for containers with USER & CMD set
Browse files Browse the repository at this point in the history
  • Loading branch information
dcermak committed Aug 16, 2024
1 parent ba3070d commit 1055797
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions tests/test_container_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from pytest_container.container import ContainerData
from pytest_container.container import ContainerLauncher
from pytest_container.container import EntrypointSelection
from pytest_container.inspect import PortForwarding
from pytest_container.runtime import LOCALHOST
from pytest_container.runtime import OciRuntimeBase

Expand Down Expand Up @@ -47,6 +48,19 @@

LEAP2 = DerivedContainer(base=LEAP)

LEAP_WITH_BIN = DerivedContainer(
base=LEAP,
containerfile="""RUN zypper -n in system-user-bin
USER bin
""",
)

LEAP_WITH_BIN_AND_CMD = DerivedContainer(
base=LEAP_WITH_BIN,
containerfile="""CMD ["/usr/bin/sleep", "3600"]""",
forwarded_ports=[PortForwarding(container_port=8080)],
)

CONTAINER_IMAGES = [LEAP, LEAP_WITH_MAN, LEAP_WITH_MAN_AND_LUA]

MULTI_STAGE_BUILD = MultiStageBuild(
Expand Down Expand Up @@ -214,6 +228,32 @@ def test_container_size(
)


@pytest.mark.parametrize(
"container",
(LEAP_WITH_BIN, LEAP_WITH_BIN_AND_CMD),
indirect=True,
)
def test_derived_containers_use_correct_user(
container: ContainerData,
) -> None:
assert container.connection.check_output("id -nu").strip() == "bin"
assert container.inspect.config.user == "bin"


@pytest.mark.parametrize(
"container",
[
DerivedContainer(base=ctr, extra_launch_args=["--user", "root"])
for ctr in (LEAP_WITH_BIN, LEAP_WITH_BIN_AND_CMD)
],
indirect=True,
)
def test_derived_container_respects_launch_args(
container: ContainerData,
) -> None:
assert int(container.connection.check_output("id -u").strip()) == 0


def test_multistage_containerfile() -> None:
assert "FROM docker.io/alpine" in MULTI_STAGE_BUILD.containerfile

Expand Down

0 comments on commit 1055797

Please sign in to comment.