diff --git a/tests/integration/env-tests/container-compose.yml b/tests/integration/env-tests/container-compose.yml index 3a8b28e..4498f09 100644 --- a/tests/integration/env-tests/container-compose.yml +++ b/tests/integration/env-tests/container-compose.yml @@ -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} diff --git a/tests/integration/env-tests/test_podman_compose_env.py b/tests/integration/env-tests/test_podman_compose_env.py index 351644f..3d50a07 100644 --- a/tests/integration/env-tests/test_podman_compose_env.py +++ b/tests/integration/env-tests/test_podman_compose_env.py @@ -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", + ])