moby/daemon/images/images_test.go
Brian Goff 50f39e7247 Move cpu variant checks into platform matcher
Wrap platforms.Only and fallback to our ignore mismatches due to  empty
CPU variants. This just cleans things up and makes the logic re-usable
in other places.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2021-02-18 16:58:48 +00:00

33 lines
755 B
Go

package images
import (
"testing"
specs "github.com/opencontainers/image-spec/specs-go/v1"
"gotest.tools/v3/assert"
)
func TestOnlyPlatformWithFallback(t *testing.T) {
p := specs.Platform{
OS: "linux",
Architecture: "arm",
Variant: "v8",
}
// Check no variant
assert.Assert(t, OnlyPlatformWithFallback(p).Match(specs.Platform{
OS: p.OS,
Architecture: p.Architecture,
}))
// check with variant
assert.Assert(t, OnlyPlatformWithFallback(p).Match(specs.Platform{
OS: p.OS,
Architecture: p.Architecture,
Variant: p.Variant,
}))
// Make sure non-matches are false.
assert.Assert(t, !OnlyPlatformWithFallback(p).Match(specs.Platform{
OS: p.OS,
Architecture: "amd64",
}))
}