diff --git a/frontend/dockerfile/dockerfile_namedcontext_test.go b/frontend/dockerfile/dockerfile_namedcontext_test.go index 168ce8ddbf7fe..690d60fb5b6a9 100644 --- a/frontend/dockerfile/dockerfile_namedcontext_test.go +++ b/frontend/dockerfile/dockerfile_namedcontext_test.go @@ -1,13 +1,16 @@ package dockerfile import ( + "math" "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/pkg/errors" "github.com/stretchr/testify/require" + "golang.org/x/sync/errgroup" ) func testNamedFilteredContext(t *testing.T, sb integration.Sandbox) { @@ -41,32 +44,65 @@ COPY --link --from=d /bar /foo.d dir := integration.Tmpdir( t, - fstest.CreateFile("Dockerfile", dockerfile, 0600), + fstest.CreateFile(dockerui.DefaultDockerfileName, dockerfile, 0600), ) - dir2 := integration.Tmpdir(t) + dir2 := integration.Tmpdir(t, + // small file + fstest.CreateFile("foo", []byte(`foo`), 0600), + // blank file that's just large + fstest.CreateFile("bar", make([]byte, 4096*1000), 0600), + ) f := getFrontend(t, sb) - runTest := func(t *testing.T, target string, maxTransfer float64) { + runTest := func(t *testing.T, target string, min, max int64) { 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) + ch := make(chan *client.SolveStatus) + + eg, ctx := errgroup.WithContext(sb.Context()) + eg.Go(func() error { + _, err := f.Solve(ctx, c, client.SolveOpt{ + FrontendAttrs: map[string]string{ + "context:a": "local:a", + "target": target, + }, + LocalDirs: map[string]string{ + dockerui.DefaultLocalNameDockerfile: dir, + dockerui.DefaultLocalNameContext: dir, + "a": dir2, + }, + }, ch) + return err + }) + + eg.Go(func() error { + var transferred int64 + for ss := range ch { + for _, status := range ss.Statuses { + if status.Name != "transferring" && status.Completed == nil { + continue + } + transferred += status.Current + } + } + + t.Logf("transferred %d bytes", transferred) + if transferred < min { + return errors.Errorf("not enough data was transferred, %d < %d", transferred, min) + } else if transferred > max { + return errors.Errorf("too much data was transferred, %d > %d", transferred, max) + } + return nil + }) + + err := eg.Wait() require.NoError(t, err) }) } - runTest(t, "run_mount", 0) - runTest(t, "copy_from", 0) - runTest(t, "image_source", 0) - runTest(t, "all", 0) + runTest(t, "run_mount", 1, 1024) + runTest(t, "copy_from", 1, 1024) + runTest(t, "image_source", 4096*1000, math.MaxInt64) + runTest(t, "all", 4096*1000, math.MaxInt64) }