Skip to content

Commit

Permalink
starting some work on the unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
jsternberg committed Sep 18, 2023
1 parent 32b557d commit 8569e69
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
72 changes: 72 additions & 0 deletions frontend/dockerfile/dockerfile_namedcontext_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package dockerfile

import (
"testing"

"github.com/containerd/continuity/fs/fstest"
"github.com/moby/buildkit/client"
"github.com/moby/buildkit/frontend/dockerui"
"github.com/moby/buildkit/util/testutil/integration"
"github.com/stretchr/testify/require"
)

func testNamedFilteredContext(t *testing.T, sb integration.Sandbox) {
// need to test
// using run --mount, copy --from, and as image source
// the above
ctx := sb.Context()

c, err := client.New(ctx, sb.Address())
require.NoError(t, err)
defer c.Close()

dockerfile := []byte(`
FROM alpine AS foo
RUN echo test > /foo
FROM scratch AS copy_from
COPY --from=foo /foo /
FROM alpine AS run_mount
RUN --mount=from=foo,target=/in cp /in/foo /foo
FROM foo AS image_source
RUN cat /foo > /bar
FROM scratch AS all
COPY --link --from=b /foo /foo.b
COPY --link --from=c /foo /foo.c
COPY --link --from=d /bar /foo.d
`)

dir := integration.Tmpdir(
t,
fstest.CreateFile("Dockerfile", dockerfile, 0600),
)

dir2 := integration.Tmpdir(t)

f := getFrontend(t, sb)

runTest := func(t *testing.T, target string, maxTransfer float64) {
t.Run(target, func(t *testing.T) {
_, err := f.Solve(ctx, c, client.SolveOpt{
FrontendAttrs: map[string]string{
"context:a": "local:a",
"target": target,
},
LocalDirs: map[string]string{
dockerui.DefaultDockerfileName: dir,
dockerui.DefaultLocalNameContext: dir,
"a": dir2,
},
}, nil)
require.NoError(t, err)
})
}

runTest(t, "run_mount", 0)
runTest(t, "copy_from", 0)
runTest(t, "image_source", 0)
runTest(t, "all", 0)
}
1 change: 1 addition & 0 deletions frontend/dockerfile/dockerfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ var allTests = integration.TestFuncs(
testNamedOCILayoutContextExport,
testNamedInputContext,
testNamedMultiplatformInputContext,
testNamedFilteredContext,
testEmptyDestDir,
testCopyChownCreateDest,
testCopyThroughSymlinkContext,
Expand Down

0 comments on commit 8569e69

Please sign in to comment.