2017-06-19 20:39:00 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"path/filepath"
|
2017-07-12 05:08:53 +00:00
|
|
|
"runtime"
|
2017-06-19 20:39:00 +00:00
|
|
|
"syscall"
|
|
|
|
"testing"
|
|
|
|
|
2017-06-22 20:15:46 +00:00
|
|
|
"github.com/moby/buildkit/client/llb"
|
2017-06-19 20:39:00 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
var clientAddressStandalone string
|
|
|
|
var clientAddressContainerd string
|
|
|
|
|
|
|
|
func TestMain(m *testing.M) {
|
|
|
|
if testing.Short() {
|
|
|
|
os.Exit(m.Run())
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup, err := setupStandalone()
|
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintln(os.Stderr, err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
cleanup, err = setupContainerd()
|
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintln(os.Stderr, err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
os.Exit(m.Run())
|
|
|
|
}
|
|
|
|
|
|
|
|
func runBuildd(args []string) (string, func(), error) {
|
|
|
|
tmpdir, err := ioutil.TempDir("", "buildd")
|
|
|
|
if err != nil {
|
|
|
|
return "", nil, err
|
|
|
|
}
|
|
|
|
defer os.RemoveAll(tmpdir)
|
|
|
|
|
|
|
|
address := filepath.Join(tmpdir, "buildd.sock")
|
2017-07-12 05:08:53 +00:00
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
address = "//./pipe/buildd-" + filepath.Base(tmpdir)
|
2017-09-21 15:49:26 +00:00
|
|
|
} else {
|
|
|
|
address = "unix://" + address
|
2017-07-12 05:08:53 +00:00
|
|
|
}
|
2017-06-19 20:39:00 +00:00
|
|
|
|
2017-09-21 15:49:26 +00:00
|
|
|
args = append(args, "--root", tmpdir, "--addr", address, "--debug")
|
2017-06-19 20:39:00 +00:00
|
|
|
|
|
|
|
cmd := exec.Command(args[0], args[1:]...)
|
2017-06-22 16:16:23 +00:00
|
|
|
// cmd.Stderr = os.Stdout
|
|
|
|
// cmd.Stdout = os.Stdout
|
2017-06-19 20:39:00 +00:00
|
|
|
if err := cmd.Start(); err != nil {
|
|
|
|
return "", nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return address, func() {
|
|
|
|
// tear down the daemon and resources created
|
|
|
|
if err := cmd.Process.Signal(syscall.SIGTERM); err != nil {
|
|
|
|
fmt.Fprintln(os.Stderr, err)
|
|
|
|
}
|
|
|
|
if _, err := cmd.Process.Wait(); err != nil {
|
|
|
|
fmt.Fprintln(os.Stderr, err)
|
|
|
|
}
|
|
|
|
os.RemoveAll(tmpdir)
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2017-07-12 05:08:53 +00:00
|
|
|
func requiresLinux(t *testing.T) {
|
|
|
|
if runtime.GOOS != "linux" {
|
|
|
|
t.Skipf("unsupported GOOS: %s", runtime.GOOS)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-19 20:39:00 +00:00
|
|
|
func testCallDiskUsage(t *testing.T, address string) {
|
|
|
|
c, err := New(address)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
_, err = c.DiskUsage(context.TODO())
|
|
|
|
assert.Nil(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testBuildMultiMount(t *testing.T, address string) {
|
2017-07-12 05:08:53 +00:00
|
|
|
requiresLinux(t)
|
2017-06-19 20:39:00 +00:00
|
|
|
t.Parallel()
|
|
|
|
c, err := New(address)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
|
|
|
|
alpine := llb.Image("docker.io/library/alpine:latest")
|
2017-06-21 21:48:21 +00:00
|
|
|
ls := alpine.Run(llb.Shlex("/bin/ls -l"))
|
2017-06-19 20:39:00 +00:00
|
|
|
busybox := llb.Image("docker.io/library/busybox:latest")
|
2017-06-21 21:48:21 +00:00
|
|
|
cp := ls.Run(llb.Shlex("/bin/cp -a /busybox/etc/passwd baz"))
|
2017-06-19 20:39:00 +00:00
|
|
|
cp.AddMount("/busybox", busybox)
|
|
|
|
|
2017-10-02 04:59:34 +00:00
|
|
|
def, err := cp.Marshal()
|
2017-06-19 20:39:00 +00:00
|
|
|
assert.Nil(t, err)
|
|
|
|
|
2017-10-02 04:59:34 +00:00
|
|
|
err = c.Solve(context.TODO(), def, SolveOpt{}, nil)
|
2017-06-19 20:39:00 +00:00
|
|
|
assert.Nil(t, err)
|
|
|
|
}
|