dockerfile: add example mount test
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>docker-18.09
parent
1be3e43527
commit
74754d6a6a
|
@ -0,0 +1,51 @@
|
|||
// +build dfrunmount
|
||||
|
||||
package dockerfile
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/containerd/continuity/fs/fstest"
|
||||
"github.com/moby/buildkit/client"
|
||||
"github.com/moby/buildkit/frontend/dockerfile/builder"
|
||||
"github.com/moby/buildkit/util/testutil/integration"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
var mountTests = []integration.Test{
|
||||
testMountContext,
|
||||
}
|
||||
|
||||
func init() {
|
||||
allTests = append(allTests, mountTests...)
|
||||
}
|
||||
|
||||
func testMountContext(t *testing.T, sb integration.Sandbox) {
|
||||
f := getFrontend(t, sb)
|
||||
|
||||
dockerfile := []byte(`
|
||||
FROM busybox
|
||||
RUN --mount=target=/context [ "$(cat /context/testfile)" == "contents0" ]
|
||||
`)
|
||||
|
||||
dir, err := tmpdir(
|
||||
fstest.CreateFile("Dockerfile", dockerfile, 0600),
|
||||
fstest.CreateFile("testfile", []byte("contents0"), 0600),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
defer os.RemoveAll(dir)
|
||||
|
||||
c, err := client.New(context.TODO(), sb.Address())
|
||||
require.NoError(t, err)
|
||||
defer c.Close()
|
||||
|
||||
_, err = f.Solve(context.TODO(), c, client.SolveOpt{
|
||||
LocalDirs: map[string]string{
|
||||
builder.LocalNameDockerfile: dir,
|
||||
builder.LocalNameContext: dir,
|
||||
},
|
||||
}, nil)
|
||||
require.NoError(t, err)
|
||||
}
|
|
@ -37,43 +37,7 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
var opts []integration.TestOpt
|
||||
|
||||
type frontend interface {
|
||||
Solve(context.Context, *client.Client, client.SolveOpt, chan *client.SolveStatus) (*client.SolveResponse, error)
|
||||
DFCmdArgs(string, string) (string, string)
|
||||
RequiresBuildctl(t *testing.T)
|
||||
}
|
||||
|
||||
func init() {
|
||||
frontends := map[string]interface{}{}
|
||||
|
||||
opts = []integration.TestOpt{
|
||||
integration.WithMirroredImages(integration.OfficialImages("busybox:latest")),
|
||||
integration.WithMirroredImages(map[string]string{
|
||||
"tonistiigi/copy:v0.1.7": "docker.io/" + dockerfile2llb.DefaultCopyImage,
|
||||
}),
|
||||
integration.WithMatrix("frontend", frontends),
|
||||
}
|
||||
|
||||
if os.Getenv("FRONTEND_BUILTIN_ONLY") == "1" {
|
||||
frontends["builtin"] = &builtinFrontend{}
|
||||
} else if os.Getenv("FRONTEND_CLIENT_ONLY") == "1" {
|
||||
frontends["client"] = &clientFrontend{}
|
||||
} else if gw := os.Getenv("FRONTEND_GATEWAY_ONLY"); gw != "" {
|
||||
name := "buildkit_test/" + identity.NewID() + ":latest"
|
||||
opts = append(opts, integration.WithMirroredImages(map[string]string{
|
||||
name: gw,
|
||||
}))
|
||||
frontends["gateway"] = &gatewayFrontend{gw: name}
|
||||
} else {
|
||||
frontends["builtin"] = &builtinFrontend{}
|
||||
frontends["client"] = &clientFrontend{}
|
||||
}
|
||||
}
|
||||
|
||||
func TestIntegration(t *testing.T) {
|
||||
integration.Run(t, []integration.Test{
|
||||
var allTests = []integration.Test{
|
||||
testNoSnapshotLeak,
|
||||
testCmdShell,
|
||||
testGlobalArg,
|
||||
|
@ -116,7 +80,45 @@ func TestIntegration(t *testing.T) {
|
|||
testCopyThroughSymlinkMultiStage,
|
||||
testCopyChownCreateDest,
|
||||
testEmptyDestDir,
|
||||
}, opts...)
|
||||
}
|
||||
|
||||
var opts []integration.TestOpt
|
||||
|
||||
type frontend interface {
|
||||
Solve(context.Context, *client.Client, client.SolveOpt, chan *client.SolveStatus) (*client.SolveResponse, error)
|
||||
DFCmdArgs(string, string) (string, string)
|
||||
RequiresBuildctl(t *testing.T)
|
||||
}
|
||||
|
||||
func init() {
|
||||
frontends := map[string]interface{}{}
|
||||
|
||||
opts = []integration.TestOpt{
|
||||
integration.WithMirroredImages(integration.OfficialImages("busybox:latest")),
|
||||
integration.WithMirroredImages(map[string]string{
|
||||
"tonistiigi/copy:v0.1.7": "docker.io/" + dockerfile2llb.DefaultCopyImage,
|
||||
}),
|
||||
integration.WithMatrix("frontend", frontends),
|
||||
}
|
||||
|
||||
if os.Getenv("FRONTEND_BUILTIN_ONLY") == "1" {
|
||||
frontends["builtin"] = &builtinFrontend{}
|
||||
} else if os.Getenv("FRONTEND_CLIENT_ONLY") == "1" {
|
||||
frontends["client"] = &clientFrontend{}
|
||||
} else if gw := os.Getenv("FRONTEND_GATEWAY_ONLY"); gw != "" {
|
||||
name := "buildkit_test/" + identity.NewID() + ":latest"
|
||||
opts = append(opts, integration.WithMirroredImages(map[string]string{
|
||||
name: gw,
|
||||
}))
|
||||
frontends["gateway"] = &gatewayFrontend{gw: name}
|
||||
} else {
|
||||
frontends["builtin"] = &builtinFrontend{}
|
||||
frontends["client"] = &clientFrontend{}
|
||||
}
|
||||
}
|
||||
|
||||
func TestIntegration(t *testing.T) {
|
||||
integration.Run(t, allTests, opts...)
|
||||
}
|
||||
|
||||
func testEmptyDestDir(t *testing.T, sb integration.Sandbox) {
|
||||
|
|
Loading…
Reference in New Issue