tests: add TestBakeDisableEnvLookup

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
Tonis Tiigi
2026-01-15 22:46:30 -08:00
parent 8b1f6fd8c0
commit 88359c58a0
+69
View File
@@ -82,6 +82,7 @@ var bakeTests = []func(t *testing.T, sb integration.Sandbox){
testBakeCheckCallOutput,
testBakeExtraHosts,
testBakeFileFromEnvironment,
testBakeDisableEnvLookup,
}
func testBakePrint(t *testing.T, sb integration.Sandbox) {
@@ -173,6 +174,74 @@ RUN echo "Hello ${HELLO}"
}
}
func testBakeDisableEnvLookup(t *testing.T, sb integration.Sandbox) {
testCases := []struct {
name string
f string
dt []byte
}{
{
name: "HCL",
f: "docker-bake.hcl",
dt: []byte(`
variable "HELLO" {
default = "fallback"
}
target "build" {
args = {
HELLO = HELLO
}
}
`),
},
{
name: "Compose",
f: "compose.yml",
dt: []byte(`
services:
build:
build:
context: .
args:
HELLO: ${HELLO:-fallback}
`),
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
dir := tmpdir(
t,
fstest.CreateFile(tc.f, tc.dt, 0600),
fstest.CreateFile("Dockerfile", []byte(`
FROM busybox
ARG HELLO
RUN echo "Hello ${HELLO}"
`), 0600),
)
cmd := buildxCmd(
sb,
withDir(dir),
withArgs("bake", "--print", "build"),
withEnv(
"BUILDX_BAKE_DISABLE_VARS_ENV_LOOKUP=1",
"HELLO=fromenv",
),
)
stdout := bytes.Buffer{}
stderr := bytes.Buffer{}
cmd.Stdout = &stdout
cmd.Stderr = &stderr
require.NoError(t, cmd.Run(), stdout.String(), stderr.String())
require.Contains(t, stdout.String(), `"HELLO": "fallback"`)
require.NotContains(t, stdout.String(), "fromenv")
})
}
}
func testBakePrintSensitive(t *testing.T, sb integration.Sandbox) {
testCases := []struct {
name string