Skip to content

Commit 97856c8

Browse files
committed
Add tests for self-referencing variables in environment files
Signed-off-by: Artem Lytkin <iprintercanon@gmail.com>
1 parent f9828df commit 97856c8

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

pkg/e2e/compose_environment_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,24 @@ func TestEnvInterpolation(t *testing.T) {
205205
})
206206
}
207207

208+
func TestEnvSelfReference(t *testing.T) {
209+
c := NewParallelCLI(t)
210+
211+
t.Run("self-referencing variables expand within env file", func(t *testing.T) {
212+
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/environment/env-self-reference/compose.yaml", "config")
213+
res.Assert(t, icmd.Expected{Out: `FULL_IMAGE: gcr.io/myproject/myapp:latest`})
214+
res.Assert(t, icmd.Expected{Out: `BASE_URL: gcr.io/myproject/subpath`})
215+
})
216+
217+
t.Run("OS env overrides base variable and cascades through references", func(t *testing.T) {
218+
cmd := c.NewDockerComposeCmd(t, "-f", "./fixtures/environment/env-self-reference/compose.yaml", "config")
219+
cmd.Env = append(cmd.Env, "REGISTRY_URL=override.io")
220+
res := icmd.RunCmd(cmd)
221+
res.Assert(t, icmd.Expected{Out: `FULL_IMAGE: override.io/myapp:latest`})
222+
res.Assert(t, icmd.Expected{Out: `BASE_URL: override.io/subpath`})
223+
})
224+
}
225+
208226
func TestCommentsInEnvFile(t *testing.T) {
209227
c := NewParallelCLI(t)
210228

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
REGISTRY_URL=gcr.io/myproject
2+
IMAGE_NAME=myapp
3+
FULL_IMAGE=${REGISTRY_URL}/${IMAGE_NAME}:latest
4+
BASE_URL=${REGISTRY_URL}/subpath
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
services:
2+
test:
3+
image: bash
4+
environment:
5+
FULL_IMAGE: ${FULL_IMAGE}
6+
BASE_URL: ${BASE_URL}
7+
command: echo "ok"

0 commit comments

Comments
 (0)