Skip to content

Commit 998f003

Browse files
committed
Update integration test for checking empty dockerfile arg behavior and move from linting tests
Signed-off-by: Talon Bowler <[email protected]>
1 parent 8a254a7 commit 998f003

File tree

2 files changed

+45
-14
lines changed

2 files changed

+45
-14
lines changed

frontend/dockerfile/dockerfile_lint_test.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -786,20 +786,6 @@ ENV PATH=$PAHT:/tmp/bin
786786
},
787787
},
788788
})
789-
790-
dockerfile = []byte(`
791-
FROM alpine
792-
ARG FOO
793-
ARG BAR=
794-
RUN env | grep 'BAR='
795-
RUN env | grep 'FOO='
796-
`)
797-
checkLinterWarnings(t, sb, &lintTestParams{
798-
Dockerfile: dockerfile,
799-
StreamBuildErr: `failed to solve: process "/bin/sh -c env | grep 'FOO='" did not complete successfully: exit code: 1`,
800-
UnmarshalBuildErr: `process "/bin/sh -c env | grep 'FOO='" did not complete successfully: exit code: 1`,
801-
BuildErrLocation: 6,
802-
})
803789
}
804790

805791
func testMultipleInstructionsDisallowed(t *testing.T, sb integration.Sandbox) {

frontend/dockerfile/dockerfile_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ var allTests = integration.TestFuncs(
185185
testFrontendDeduplicateSources,
186186
testDuplicateLayersProvenance,
187187
testSourcePolicyWithNamedContext,
188+
testEmptyStringArgInEnv,
188189
)
189190

190191
// Tests that depend on the `security.*` entitlements
@@ -263,6 +264,50 @@ func TestIntegration(t *testing.T) {
263264
)...)
264265
}
265266

267+
func testEmptyStringArgInEnv(t *testing.T, sb integration.Sandbox) {
268+
integration.SkipOnPlatform(t, "windows")
269+
f := getFrontend(t, sb)
270+
271+
dockerfile := []byte(`
272+
FROM busybox AS build
273+
ARG FOO
274+
ARG BAR=
275+
RUN env > env.txt
276+
277+
FROM scratch
278+
COPY --from=build env.txt .
279+
`)
280+
dir := integration.Tmpdir(
281+
t,
282+
fstest.CreateFile("Dockerfile", dockerfile, 0600),
283+
)
284+
c, err := client.New(sb.Context(), sb.Address())
285+
require.NoError(t, err)
286+
defer c.Close()
287+
288+
destDir := t.TempDir()
289+
_, err = f.Solve(sb.Context(), c, client.SolveOpt{
290+
Exports: []client.ExportEntry{
291+
{
292+
Type: client.ExporterLocal,
293+
OutputDir: destDir,
294+
},
295+
},
296+
LocalMounts: map[string]fsutil.FS{
297+
dockerui.DefaultLocalNameDockerfile: dir,
298+
dockerui.DefaultLocalNameContext: dir,
299+
},
300+
}, nil)
301+
require.NoError(t, err)
302+
303+
dt, err := os.ReadFile(filepath.Join(destDir, "env.txt"))
304+
require.NoError(t, err)
305+
306+
envStr := string(dt)
307+
require.Contains(t, envStr, "BAR=")
308+
require.NotContains(t, envStr, "FOO=")
309+
}
310+
266311
func testDefaultEnvWithArgs(t *testing.T, sb integration.Sandbox) {
267312
integration.SkipOnPlatform(t, "windows")
268313
f := getFrontend(t, sb)

0 commit comments

Comments
 (0)