From 02d01c035027d23a00d89b6e7d002c704c708062 Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Thu, 30 Nov 2017 16:28:35 -0800 Subject: [PATCH] buildctl: add integration test for local exporter Signed-off-by: Tonis Tiigi --- cmd/buildctl/build_test.go | 29 ++++++++++++++++++++++++++++- cmd/buildctl/buildctl_test.go | 1 + 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/cmd/buildctl/build_test.go b/cmd/buildctl/build_test.go index de54a8cf..aaf21ef9 100644 --- a/cmd/buildctl/build_test.go +++ b/cmd/buildctl/build_test.go @@ -6,6 +6,7 @@ import ( "io" "io/ioutil" "os" + "path/filepath" "testing" "github.com/containerd/containerd/fs/fstest" @@ -15,6 +16,7 @@ import ( ) func testBuildWithLocalFiles(t *testing.T, sb integration.Sandbox) { + t.Parallel() dir, err := tmpdir( fstest.CreateFile("foo", []byte("bar"), 0600), ) @@ -37,6 +39,31 @@ func testBuildWithLocalFiles(t *testing.T, sb integration.Sandbox) { require.NoError(t, err) } +func testBuildLocalExporter(t *testing.T, sb integration.Sandbox) { + t.Parallel() + st := llb.Image("busybox"). + Run(llb.Shlex("sh -c 'echo -n bar > /out/foo'")) + + out := st.AddMount("/out", llb.Scratch()) + + rdr, err := marshal(out) + require.NoError(t, err) + + tmpdir, err := ioutil.TempDir("", "buildkit-buildctl") + require.NoError(t, err) + defer os.RemoveAll(tmpdir) + + cmd := sb.Cmd(fmt.Sprintf("build --no-progress --exporter=local --exporter-opt output=%s", tmpdir)) + cmd.Stdin = rdr + err = cmd.Run() + + require.NoError(t, err) + + dt, err := ioutil.ReadFile(filepath.Join(tmpdir, "foo")) + require.NoError(t, err) + require.Equal(t, string(dt), "bar") +} + func marshal(st llb.State) (io.Reader, error) { def, err := st.Marshal() if err != nil { @@ -50,7 +77,7 @@ func marshal(st llb.State) (io.Reader, error) { } func tmpdir(appliers ...fstest.Applier) (string, error) { - tmpdir, err := ioutil.TempDir("", "buildkit-dockerfile") + tmpdir, err := ioutil.TempDir("", "buildkit-buildctl") if err != nil { return "", err } diff --git a/cmd/buildctl/buildctl_test.go b/cmd/buildctl/buildctl_test.go index 97a4730b..e781384f 100644 --- a/cmd/buildctl/buildctl_test.go +++ b/cmd/buildctl/buildctl_test.go @@ -10,5 +10,6 @@ func TestCLIIntegration(t *testing.T) { integration.Run(t, []integration.Test{ testDiskUsage, testBuildWithLocalFiles, + testBuildLocalExporter, }) }