test/integration: Test COMPOSE_PROJECT_NAME interpolation

Refs #1073

Signed-off-by: Ruben Jenster <r.jenster@drachenfels.de>
This commit is contained in:
Ruben Jenster 2025-03-12 16:20:58 +01:00 committed by Ruben Jenster
parent 52e2912e0b
commit 170411de8b
2 changed files with 39 additions and 0 deletions

View File

@ -1,5 +1,7 @@
version: "3"
name: my-project-name
services:
env-test:
image: busybox
@ -8,3 +10,9 @@ services:
ZZVAR1: myval1
ZZVAR2: 2-$ZZVAR1
ZZVAR3: 3-$ZZVAR2
project-name-test:
image: busybox
command: sh -c "echo $$PNAME"
environment:
PNAME: ${COMPOSE_PROJECT_NAME}

View File

@ -36,3 +36,34 @@ class TestComposeEnv(unittest.TestCase, RunSubprocessMixin):
compose_yaml_path(),
"down",
])
"""
Tests interpolation of COMPOSE_PROJECT_NAME in the podman-compose config,
which is different from external environment variables because COMPOSE_PROJECT_NAME
is a predefined environment variable generated from the `name` value in the top-level
of the compose.yaml.
See also
- https://docs.docker.com/reference/compose-file/interpolation/
- https://docs.docker.com/reference/compose-file/version-and-name/#name-top-level-element
- https://docs.docker.com/compose/how-tos/environment-variables/envvars/
- https://github.com/compose-spec/compose-spec/blob/main/04-version-and-name.md
"""
def test_project_name(self):
try:
output, _ = self.run_subprocess_assert_returncode([
podman_compose_path(),
"-f",
compose_yaml_path(),
"run",
"project-name-test",
])
self.assertIn("my-project-name", str(output))
finally:
self.run_subprocess_assert_returncode([
podman_compose_path(),
"-f",
compose_yaml_path(),
"down",
])