Merge pull request #1987 from jedevc/vendor-buildkit-master-tests

This commit is contained in:
Justin Chadwell
2023-08-07 17:08:16 +01:00
committed by GitHub
36 changed files with 784 additions and 666 deletions

View File

@@ -141,7 +141,7 @@ func testImageIDOutput(t *testing.T, sb integration.Sandbox) {
outFlag := "--output=type=docker"
if sb.Name() == "remote" {
if sb.DockerAddress() == "" {
// there is no Docker atm to load the image
outFlag += ",dest=" + targetDir + "/image.tar"
}
@@ -210,14 +210,15 @@ func testBuildMobyFromLocalImage(t *testing.T, sb integration.Sandbox) {
require.NoError(t, cmd.Run())
// create local tag matching a remote one
cmd = dockerCmd(sb, withArgs("tag", "busybox:latest", "busybox:1.36"))
cmd = dockerCmd(sb, withArgs("tag", "busybox:latest", "busybox:1.35"))
cmd.Stderr = os.Stderr
require.NoError(t, cmd.Run())
// build image and check that it uses the local tag
// (note: the version check should match the version of busybox in pins.go)
dockerfile = []byte(`
FROM busybox:1.36
RUN busybox | head -1 | grep v1.35.0
FROM busybox:1.35
RUN busybox | head -1 | grep v1.36.1
`)
dir = tmpdir(t, fstest.CreateFile("Dockerfile", dockerfile, 0600))
cmd = buildxCmd(

View File

@@ -7,10 +7,11 @@ import (
"github.com/docker/buildx/tests/workers"
"github.com/docker/distribution/reference"
"github.com/moby/buildkit/util/testutil/integration"
bkworkers "github.com/moby/buildkit/util/testutil/workers"
)
func init() {
if integration.IsTestDockerd() {
if bkworkers.IsTestDockerd() {
workers.InitDockerWorker()
workers.InitDockerContainerWorker()
} else {
@@ -32,7 +33,7 @@ func TestIntegration(t *testing.T) {
func testIntegration(t *testing.T, funcs ...func(t *testing.T, sb integration.Sandbox)) {
mirroredImages := integration.OfficialImages("busybox:latest", "alpine:latest")
buildkitImage := "docker.io/moby/buildkit:buildx-stable-1"
if integration.IsTestDockerd() {
if bkworkers.IsTestDockerd() {
if img, ok := os.LookupEnv("TEST_BUILDKIT_IMAGE"); ok {
ref, err := reference.ParseNormalizedNamed(img)
if err == nil {

View File

@@ -1,10 +1,20 @@
package workers
import (
"os"
"strings"
"github.com/moby/buildkit/util/testutil/integration"
)
type backend struct {
builder string
context string
builder string
context string
unsupportedFeatures []string
}
var _ integration.Backend = &backend{}
func (s *backend) Address() string {
return s.builder
}
@@ -24,3 +34,26 @@ func (s *backend) Snapshotter() string {
func (s *backend) Rootless() bool {
return false
}
func (s backend) Supports(feature string) bool {
if enabledFeatures := os.Getenv("BUILDKIT_TEST_ENABLE_FEATURES"); enabledFeatures != "" {
for _, enabledFeature := range strings.Split(enabledFeatures, ",") {
if feature == enabledFeature {
return true
}
}
}
if disabledFeatures := os.Getenv("BUILDKIT_TEST_DISABLE_FEATURES"); disabledFeatures != "" {
for _, disabledFeature := range strings.Split(disabledFeatures, ",") {
if feature == disabledFeature {
return false
}
}
}
for _, unsupportedFeature := range s.unsupportedFeatures {
if feature == unsupportedFeature {
return false
}
}
return true
}

View File

@@ -20,6 +20,8 @@ func InitDockerContainerWorker() {
type containerWorker struct {
id string
unsupported []string
docker integration.Backend
dockerClose func() error
dockerErr error
@@ -65,8 +67,9 @@ func (w *containerWorker) New(ctx context.Context, cfg *integration.BackendConfi
}
return &backend{
context: w.docker.DockerAddress(),
builder: name,
context: w.docker.DockerAddress(),
builder: name,
unsupportedFeatures: w.unsupported,
}, cl, nil
}

View File

@@ -7,6 +7,7 @@ import (
"github.com/moby/buildkit/identity"
"github.com/moby/buildkit/util/testutil/integration"
bkworkers "github.com/moby/buildkit/util/testutil/workers"
"github.com/pkg/errors"
)
@@ -23,6 +24,7 @@ func InitDockerWorker() {
type dockerWorker struct {
id string
containerdSnapshotter bool
unsupported []string
}
func (c dockerWorker) Name() string {
@@ -34,7 +36,7 @@ func (c dockerWorker) Rootless() bool {
}
func (c dockerWorker) New(ctx context.Context, cfg *integration.BackendConfig) (b integration.Backend, cl func() error, err error) {
moby := integration.Moby{
moby := bkworkers.Moby{
ID: c.id,
ContainerdSnapshotter: c.containerdSnapshotter,
}
@@ -66,8 +68,9 @@ func (c dockerWorker) New(ctx context.Context, cfg *integration.BackendConfig) (
}
return &backend{
builder: name,
context: name,
builder: name,
context: name,
unsupportedFeatures: c.unsupported,
}, cl, nil
}

13
tests/workers/features.go Normal file
View File

@@ -0,0 +1,13 @@
package workers
import (
"testing"
"github.com/moby/buildkit/util/testutil/integration"
)
var features = map[string]struct{}{}
func CheckFeatureCompat(t *testing.T, sb integration.Sandbox, reason ...string) {
integration.CheckFeatureCompat(t, sb, features, reason...)
}

View File

@@ -7,6 +7,7 @@ import (
"github.com/moby/buildkit/identity"
"github.com/moby/buildkit/util/testutil/integration"
bkworkers "github.com/moby/buildkit/util/testutil/workers"
"github.com/pkg/errors"
)
@@ -17,7 +18,8 @@ func InitRemoteWorker() {
}
type remoteWorker struct {
id string
id string
unsupported []string
}
func (w remoteWorker) Name() string {
@@ -29,7 +31,7 @@ func (w remoteWorker) Rootless() bool {
}
func (w remoteWorker) New(ctx context.Context, cfg *integration.BackendConfig) (b integration.Backend, cl func() error, err error) {
oci := integration.OCI{ID: w.id}
oci := bkworkers.OCI{ID: w.id}
bk, bkclose, err := oci.New(ctx, cfg)
if err != nil {
return bk, cl, err
@@ -60,7 +62,8 @@ func (w remoteWorker) New(ctx context.Context, cfg *integration.BackendConfig) (
}
return &backend{
builder: name,
builder: name,
unsupportedFeatures: w.unsupported,
}, cl, nil
}