add optional check that snapshotter supports the image platform when unpacking

Signed-off-by: Kathryn Baldauf <kabaldau@microsoft.com>
This commit is contained in:
Kathryn Baldauf
2019-08-29 15:57:12 -07:00
parent 1e624fa3de
commit f8992f451c
7 changed files with 150 additions and 6 deletions

View File

@@ -81,6 +81,9 @@ func TestImageIsUnpacked(t *testing.T) {
}
func TestImagePullWithDistSourceLabel(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip()
}
var (
source = "docker.io"
repoName = "library/busybox"
@@ -233,3 +236,39 @@ func TestImageUsage(t *testing.T) {
t.Fatalf("Expected actual usage with snapshots to be greater: %d <= %d", s, s3)
}
}
func TestImageSupportedBySnapshotter_Error(t *testing.T) {
var unsupportedImage string
if runtime.GOOS == "windows" {
unsupportedImage = "docker.io/library/busybox:latest"
} else {
unsupportedImage = "mcr.microsoft.com/windows/nanoserver:1809"
}
ctx, cancel := testContext(t)
defer cancel()
client, err := newClient(t, address)
if err != nil {
t.Fatal(err)
}
defer client.Close()
// Cleanup
err = client.ImageService().Delete(ctx, unsupportedImage)
if err != nil && !errdefs.IsNotFound(err) {
t.Fatal(err)
}
_, err = client.Pull(ctx, unsupportedImage,
WithSchema1Conversion,
WithPlatform(platforms.DefaultString()),
WithPullSnapshotter(DefaultSnapshotter),
WithPullUnpack,
WithUnpackOpts([]UnpackOpt{WithSnapshotterPlatformCheck()}),
)
if err == nil {
t.Fatalf("expected unpacking %s for snapshotter %s to fail", unsupportedImage, DefaultSnapshotter)
}
}