-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
testutil: move CheckContainerdVersion to a separate package
This function was introduced in 601dd5b, but brings in "containerd" as a dependency for testutil/integration, which results in many (indirect) dependencies. Signed-off-by: Sebastiaan van Stijn <github@gone.nl> (cherry picked from commit 619a20d) Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
- Loading branch information
Showing
3 changed files
with
41 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters