MCPcopy
hub / github.com/docker/compose / TestEnvPriority

Function TestEnvPriority

pkg/e2e/compose_environment_test.go:27–190  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

25)
26
27func TestEnvPriority(t *testing.T) {
28 c := NewParallelCLI(t)
29
30 t.Run("up", func(t *testing.T) {
31 c.RunDockerOrExitError(t, "rmi", "env-compose-priority")
32 c.RunDockerComposeCmd(t, "-f", "./fixtures/environment/env-priority/compose-with-env.yaml",
33 "up", "-d", "--build")
34 })
35
36 // Full options activated
37 // 1. Command Line (docker compose run --env <KEY[=VAL]>) <-- Result expected (From OS Environment)
38 // 2. Compose File (service::environment section)
39 // 3. Compose File (service::env_file section file)
40 // 4. Container Image ENV directive
41 // 5. Variable is not defined
42 t.Run("compose file priority", func(t *testing.T) {
43 cmd := c.NewDockerComposeCmd(t, "-f", "./fixtures/environment/env-priority/compose-with-env.yaml",
44 "--env-file", "./fixtures/environment/env-priority/.env.override",
45 "run", "--rm", "-e", "WHEREAMI", "env-compose-priority")
46 cmd.Env = append(cmd.Env, "WHEREAMI=shell")
47 res := icmd.RunCmd(cmd)
48 assert.Equal(t, strings.TrimSpace(res.Stdout()), "shell")
49 })
50
51 // Full options activated
52 // 1. Command Line (docker compose run --env <KEY[=VAL]>) <-- Result expected
53 // 2. Compose File (service::environment section)
54 // 3. Compose File (service::env_file section file)
55 // 4. Container Image ENV directive
56 // 5. Variable is not defined
57 t.Run("compose file priority", func(t *testing.T) {
58 cmd := c.NewDockerComposeCmd(t, "-f", "./fixtures/environment/env-priority/compose-with-env.yaml",
59 "--env-file", "./fixtures/environment/env-priority/.env.override",
60 "run", "--rm", "-e", "WHEREAMI=shell", "env-compose-priority")
61 res := icmd.RunCmd(cmd)
62 assert.Equal(t, strings.TrimSpace(res.Stdout()), "shell")
63 })
64
65 // No Compose file, all other options
66 // 1. Command Line (docker compose run --env <KEY[=VAL]>) <-- Result expected (From OS Environment)
67 // 2. Compose File (service::environment section)
68 // 3. Compose File (service::env_file section file)
69 // 4. Container Image ENV directive
70 // 5. Variable is not defined
71 t.Run("shell priority", func(t *testing.T) {
72 cmd := c.NewDockerComposeCmd(t, "-f", "./fixtures/environment/env-priority/compose.yaml",
73 "--env-file", "./fixtures/environment/env-priority/.env.override",
74 "run", "--rm", "-e", "WHEREAMI", "env-compose-priority")
75 cmd.Env = append(cmd.Env, "WHEREAMI=shell")
76 res := icmd.RunCmd(cmd)
77 assert.Equal(t, strings.TrimSpace(res.Stdout()), "shell")
78 })
79
80 // No Compose file, all other options with env variable from OS environment
81 // 1. Command Line (docker compose run --env <KEY[=VAL]>) <-- Result expected (From environment)
82 // 2. Compose File (service::environment section)
83 // 3. Compose File (service::env_file section file)
84 // 4. Container Image ENV directive

Callers

nothing calls this directly

Calls 5

NewParallelCLIFunction · 0.85
RunDockerOrExitErrorMethod · 0.80
RunDockerComposeCmdMethod · 0.80
NewDockerComposeCmdMethod · 0.80
RunCmdMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…