Skip to content

Commit

Permalink
Merge pull request moby#4027 from thaJeztah/move_testutil
Browse files Browse the repository at this point in the history
  • Loading branch information
jedevc authored Jul 17, 2023
2 parents ee8af2d + 619a20d commit f345540
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 32 deletions.
5 changes: 3 additions & 2 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import (
"github.com/moby/buildkit/util/contentutil"
"github.com/moby/buildkit/util/entitlements"
"github.com/moby/buildkit/util/testutil"
containerdutil "github.com/moby/buildkit/util/testutil/containerd"
"github.com/moby/buildkit/util/testutil/echoserver"
"github.com/moby/buildkit/util/testutil/httpserver"
"github.com/moby/buildkit/util/testutil/integration"
Expand Down Expand Up @@ -3090,7 +3091,7 @@ func testSourceDateEpochImageExporter(t *testing.T, sb integration.Sandbox) {
t.SkipNow()
}
// https:/containerd/containerd/commit/133ddce7cf18a1db175150e7a69470dea1bb3132
integration.CheckContainerdVersion(t, cdAddress, ">= 1.7.0-beta.1")
containerdutil.CheckVersion(t, cdAddress, ">= 1.7.0-beta.1")

integration.CheckFeatureCompat(t, sb, integration.FeatureSourceDateEpoch)
requiresLinux(t)
Expand Down Expand Up @@ -6260,7 +6261,7 @@ func testSourceMapFromRef(t *testing.T, sb integration.Sandbox) {

frontend := func(ctx context.Context, c gateway.Client) (*gateway.Result, error) {
st := llb.Scratch().File(
llb.Mkdir("foo/bar", 0600), //fails because /foo doesn't exist
llb.Mkdir("foo/bar", 0600), // fails because /foo doesn't exist
sm.Location([]*pb.Range{{Start: pb.Position{Line: 3, Character: 1}}}),
)

Expand Down
38 changes: 38 additions & 0 deletions util/testutil/containerd/containerd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package containerd

import (
"context"
"testing"
"time"

"github.com/Masterminds/semver/v3"
containerdpkg "github.com/containerd/containerd"
)

func CheckVersion(t *testing.T, cdAddress, constraint string) {
t.Helper()
constraintSemVer, err := semver.NewConstraint(constraint)
if err != nil {
t.Fatal(err)
}

cdClient, err := containerdpkg.New(cdAddress, containerdpkg.WithTimeout(60*time.Second))
if err != nil {
t.Fatal(err)
}
defer cdClient.Close()
ctx := context.TODO()
cdVersion, err := cdClient.Version(ctx)
if err != nil {
t.Fatal(err)
}

cdVersionSemVer, err := semver.NewVersion(cdVersion.Version)
if err != nil {
t.Fatal(err)
}

if !constraintSemVer.Check(cdVersionSemVer) {
t.Skipf("containerd version %q does not satisfy the constraint %q", cdVersion.Version, constraint)
}
}
30 changes: 0 additions & 30 deletions util/testutil/integration/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import (
"testing"
"time"

"github.com/Masterminds/semver/v3"
containerdpkg "github.com/containerd/containerd"
"github.com/google/shlex"
"github.com/moby/buildkit/util/bklog"
"github.com/pkg/errors"
Expand Down Expand Up @@ -369,31 +367,3 @@ func CheckFeatureCompat(t *testing.T, sb Sandbox, reason ...string) {
t.Skipf("%s worker can not currently run this test due to missing features (%s)", sb.Name(), strings.Join(ereasons, ", "))
}
}

func CheckContainerdVersion(t *testing.T, cdAddress, constraint string) {
t.Helper()
constraintSemVer, err := semver.NewConstraint(constraint)
if err != nil {
t.Fatal(err)
}

cdClient, err := containerdpkg.New(cdAddress, containerdpkg.WithTimeout(60*time.Second))
if err != nil {
t.Fatal(err)
}
defer cdClient.Close()
ctx := context.TODO()
cdVersion, err := cdClient.Version(ctx)
if err != nil {
t.Fatal(err)
}

cdVersionSemVer, err := semver.NewVersion(cdVersion.Version)
if err != nil {
t.Fatal(err)
}

if !constraintSemVer.Check(cdVersionSemVer) {
t.Skipf("containerd version %q does not satisfy the constraint %q", cdVersion.Version, constraint)
}
}

0 comments on commit f345540

Please sign in to comment.