windows: The DefaultSpec platform should match the Default matcher
The Windows Default matcher also checks the the OS Version prefix, however, the platforms.DefaultSpec does not include it, which means that it won't match the matcher. This solves the issue by adding the OS Version to the DefaultSpec. Signed-off-by: Claudiu Belu <cbelu@cloudbasesolutions.com>
This commit is contained in:
parent
af1a0908d0
commit
e2c769d6fb
@ -16,27 +16,11 @@
|
|||||||
|
|
||||||
package platforms
|
package platforms
|
||||||
|
|
||||||
import (
|
|
||||||
"runtime"
|
|
||||||
|
|
||||||
specs "github.com/opencontainers/image-spec/specs-go/v1"
|
|
||||||
)
|
|
||||||
|
|
||||||
// DefaultString returns the default string specifier for the platform.
|
// DefaultString returns the default string specifier for the platform.
|
||||||
func DefaultString() string {
|
func DefaultString() string {
|
||||||
return Format(DefaultSpec())
|
return Format(DefaultSpec())
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultSpec returns the current platform's default platform specification.
|
|
||||||
func DefaultSpec() specs.Platform {
|
|
||||||
return specs.Platform{
|
|
||||||
OS: runtime.GOOS,
|
|
||||||
Architecture: runtime.GOARCH,
|
|
||||||
// The Variant field will be empty if arch != ARM.
|
|
||||||
Variant: cpuVariant(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// DefaultStrict returns strict form of Default.
|
// DefaultStrict returns strict form of Default.
|
||||||
func DefaultStrict() MatchComparer {
|
func DefaultStrict() MatchComparer {
|
||||||
return OnlyStrict(DefaultSpec())
|
return OnlyStrict(DefaultSpec())
|
||||||
|
@ -19,6 +19,22 @@
|
|||||||
|
|
||||||
package platforms
|
package platforms
|
||||||
|
|
||||||
|
import (
|
||||||
|
"runtime"
|
||||||
|
|
||||||
|
specs "github.com/opencontainers/image-spec/specs-go/v1"
|
||||||
|
)
|
||||||
|
|
||||||
|
// DefaultSpec returns the current platform's default platform specification.
|
||||||
|
func DefaultSpec() specs.Platform {
|
||||||
|
return specs.Platform{
|
||||||
|
OS: runtime.GOOS,
|
||||||
|
Architecture: runtime.GOARCH,
|
||||||
|
// The Variant field will be empty if arch != ARM.
|
||||||
|
Variant: cpuVariant(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Default returns the default matcher for the platform.
|
// Default returns the default matcher for the platform.
|
||||||
func Default() MatchComparer {
|
func Default() MatchComparer {
|
||||||
return Only(DefaultSpec())
|
return Only(DefaultSpec())
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
//go:build !windows
|
||||||
|
// +build !windows
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Copyright The containerd Authors.
|
Copyright The containerd Authors.
|
||||||
|
|
@ -27,6 +27,18 @@ import (
|
|||||||
"golang.org/x/sys/windows"
|
"golang.org/x/sys/windows"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// DefaultSpec returns the current platform's default platform specification.
|
||||||
|
func DefaultSpec() specs.Platform {
|
||||||
|
major, minor, build := windows.RtlGetNtVersionNumbers()
|
||||||
|
return specs.Platform{
|
||||||
|
OS: runtime.GOOS,
|
||||||
|
Architecture: runtime.GOARCH,
|
||||||
|
OSVersion: fmt.Sprintf("%d.%d.%d", major, minor, build),
|
||||||
|
// The Variant field will be empty if arch != ARM.
|
||||||
|
Variant: cpuVariant(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type matchComparer struct {
|
type matchComparer struct {
|
||||||
defaults Matcher
|
defaults Matcher
|
||||||
osVersionPrefix string
|
osVersionPrefix string
|
||||||
|
@ -17,13 +17,36 @@
|
|||||||
package platforms
|
package platforms
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"reflect"
|
||||||
|
"runtime"
|
||||||
"sort"
|
"sort"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
imagespec "github.com/opencontainers/image-spec/specs-go/v1"
|
imagespec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"golang.org/x/sys/windows"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestDefault(t *testing.T) {
|
||||||
|
major, minor, build := windows.RtlGetNtVersionNumbers()
|
||||||
|
expected := imagespec.Platform{
|
||||||
|
OS: runtime.GOOS,
|
||||||
|
Architecture: runtime.GOARCH,
|
||||||
|
OSVersion: fmt.Sprintf("%d.%d.%d", major, minor, build),
|
||||||
|
Variant: cpuVariant(),
|
||||||
|
}
|
||||||
|
p := DefaultSpec()
|
||||||
|
if !reflect.DeepEqual(p, expected) {
|
||||||
|
t.Fatalf("default platform not as expected: %#v != %#v", p, expected)
|
||||||
|
}
|
||||||
|
|
||||||
|
s := DefaultString()
|
||||||
|
if s != Format(p) {
|
||||||
|
t.Fatalf("default specifier should match formatted default spec: %v != %v", s, p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestMatchComparerMatch(t *testing.T) {
|
func TestMatchComparerMatch(t *testing.T) {
|
||||||
m := matchComparer{
|
m := matchComparer{
|
||||||
defaults: Only(imagespec.Platform{
|
defaults: Only(imagespec.Platform{
|
||||||
@ -36,6 +59,10 @@ func TestMatchComparerMatch(t *testing.T) {
|
|||||||
platform imagespec.Platform
|
platform imagespec.Platform
|
||||||
match bool
|
match bool
|
||||||
}{
|
}{
|
||||||
|
{
|
||||||
|
platform: DefaultSpec(),
|
||||||
|
match: true,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
platform: imagespec.Platform{
|
platform: imagespec.Platform{
|
||||||
Architecture: "amd64",
|
Architecture: "amd64",
|
||||||
|
Loading…
Reference in New Issue
Block a user