Skip to content

Commit 106b4da

Browse files
committed
test/integration: Test COMPOSE_PROJECT_NAME interpolation
Refs #1073 Signed-off-by: Ruben Jenster <[email protected]>
1 parent 52e2912 commit 106b4da

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

tests/integration/env-tests/container-compose.yml

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
version: "3"
22

3+
name: my-project-name
4+
35
services:
46
env-test:
57
image: busybox
@@ -8,3 +10,9 @@ services:
810
ZZVAR1: myval1
911
ZZVAR2: 2-$ZZVAR1
1012
ZZVAR3: 3-$ZZVAR2
13+
14+
project-name-test:
15+
image: busybox
16+
command: sh -c "echo $$PNAME"
17+
environment:
18+
PNAME: ${COMPOSE_PROJECT_NAME}

tests/integration/env-tests/test_podman_compose_env.py

+30
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,33 @@ def test_env(self):
3636
compose_yaml_path(),
3737
"down",
3838
])
39+
40+
"""
41+
Tests interpolation of COMPOSE_PROJECT_NAME in the podman-compose config,
42+
which is different from external environment variables because COMPOSE_PROJECT_NAME
43+
is a predefined environment variable generated from the `name` value in the top-level
44+
of the compose.yaml.
45+
46+
See also
47+
- https://docs.docker.com/reference/compose-file/interpolation/
48+
- https://docs.docker.com/reference/compose-file/version-and-name/#name-top-level-element
49+
- https://docs.docker.com/compose/how-tos/environment-variables/envvars/
50+
- https://github.com/compose-spec/compose-spec/blob/main/04-version-and-name.md
51+
"""
52+
def test_project_name(self):
53+
try:
54+
output, _ = self.run_subprocess_assert_returncode([
55+
podman_compose_path(),
56+
"-f",
57+
compose_yaml_path(),
58+
"run",
59+
"project-name-test",
60+
])
61+
self.assertIn("my-project-name", str(output))
62+
finally:
63+
self.run_subprocess_assert_returncode([
64+
podman_compose_path(),
65+
"-f",
66+
compose_yaml_path(),
67+
"down",
68+
])

0 commit comments

Comments
 (0)