Merge pull request #8101 from cpuguy83/loosen_windows_platform_match

Add fallback for windows platforms without osversion
This commit is contained in:
Kevin Parsons 2023-02-14 12:17:30 -08:00 committed by GitHub
commit 9862f79eaa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 3 deletions

View File

@ -50,7 +50,10 @@ func (m windowsmatcher) Match(p specs.Platform) bool {
match := m.defaultMatcher.Match(p)
if match && m.OS == "windows" {
return strings.HasPrefix(p.OSVersion, m.osVersionPrefix) && m.defaultMatcher.Match(p)
if strings.HasPrefix(p.OSVersion, m.osVersionPrefix) {
return true
}
return p.OSVersion == ""
}
return match

View File

@ -128,7 +128,7 @@ func TestMatchComparerMatch_WCOW(t *testing.T) {
Architecture: "amd64",
OS: "windows",
},
match: false,
match: true,
},
{
platform: imagespec.Platform{
@ -251,11 +251,11 @@ func TestMatchComparerLess(t *testing.T) {
{
Architecture: "amd64",
OS: "windows",
OSVersion: "10.0.17764.1",
},
{
Architecture: "amd64",
OS: "windows",
OSVersion: "10.0.17764.1",
},
{
Architecture: "amd64",

View File

@ -19,9 +19,23 @@ package platforms
import (
"testing"
specs "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/stretchr/testify/require"
)
func TestNormalize(t *testing.T) {
require.Equal(t, DefaultSpec(), Normalize(DefaultSpec()))
}
func TestFallbackOnOSVersion(t *testing.T) {
p := specs.Platform{
OS: "windows",
Architecture: "amd64",
OSVersion: "99.99.99.99",
}
other := specs.Platform{OS: p.OS, Architecture: p.Architecture}
m := NewMatcher(p)
require.True(t, m.Match(other))
}