From 17c859f02e8008cc3a4fba44314aa35c947e3f7f Mon Sep 17 00:00:00 2001 From: Derek McGowan Date: Fri, 7 Jun 2024 15:18:56 -0700 Subject: [PATCH 1/2] Add tests for osversion matching with no version Signed-off-by: Derek McGowan --- compare_test.go | 25 +++++++++++++++++++++++-- defaults_windows_test.go | 20 ++++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/compare_test.go b/compare_test.go index cbe90de..2c276d0 100644 --- a/compare_test.go +++ b/compare_test.go @@ -78,7 +78,10 @@ func TestOnly(t *testing.T) { { platform: "windows/amd64", matches: map[bool][]string{ - true: {"windows/amd64"}, + true: { + "windows/amd64", + "windows(10.0.17763)/amd64", + }, false: { "linux/amd64", "linux/arm/v7", @@ -265,7 +268,25 @@ func TestOnlyStrict(t *testing.T) { { platform: "windows/amd64", matches: map[bool][]string{ - true: {"windows/amd64"}, + true: { + "windows/amd64", + "windows(10.0.17763)/amd64", + }, + false: { + "linux/amd64", + "linux/arm/v7", + "linux/arm64", + "windows/arm", + }, + }, + }, + { + platform: "windows(10.0.17763)/amd64", + matches: map[bool][]string{ + true: { + "windows/amd64", + "windows(10.0.17763)/amd64", + }, false: { "linux/amd64", "linux/arm/v7", diff --git a/defaults_windows_test.go b/defaults_windows_test.go index fae35bc..3e0f75f 100644 --- a/defaults_windows_test.go +++ b/defaults_windows_test.go @@ -145,6 +145,10 @@ func TestMatchComparerMatch_WCOW(t *testing.T) { // TestMatchComparerMatch_ABICheckWCOW checks windows platform matcher // behavior for stable ABI and non-stable ABI compliant versions func TestMatchComparerMatch_ABICheckWCOW(t *testing.T) { + platformNoVersion := imagespec.Platform{ + Architecture: "amd64", + OS: "windows", + } platformWS2019 := imagespec.Platform{ Architecture: "amd64", OS: "windows", @@ -160,6 +164,7 @@ func TestMatchComparerMatch_ABICheckWCOW(t *testing.T) { OS: "windows", OSVersion: "10.0.22621", } + matcherNoVersion := NewMatcher(platformNoVersion).(windowsmatcher) matcherWS2019 := windowsmatcher{ Platform: platformWS2019, osVersionPrefix: platformWS2019.OSVersion, @@ -241,6 +246,21 @@ func TestMatchComparerMatch_ABICheckWCOW(t *testing.T) { }, match: true, }, + { + hostPlatformMatcher: matcherNoVersion, + testPlatform: platformWS2019, + match: true, + }, + { + hostPlatformMatcher: matcherNoVersion, + testPlatform: platformNoVersion, + match: true, + }, + { + hostPlatformMatcher: matcherNoVersion, + testPlatform: platformWindows11, + match: true, + }, } { assert.Equal(t, test.match, test.hostPlatformMatcher.Match(test.testPlatform), "should match: %t, %s to %s", test.match, test.hostPlatformMatcher.Platform, test.testPlatform) } From 983ba156b67be3c9597b773bd1f509f0ba693c3d Mon Sep 17 00:00:00 2001 From: Derek McGowan Date: Fri, 7 Jun 2024 15:48:12 -0700 Subject: [PATCH 2/2] Update windows matcher to not compare empty os version Signed-off-by: Derek McGowan --- defaults_windows.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/defaults_windows.go b/defaults_windows.go index d10fa90..dc9a2b5 100644 --- a/defaults_windows.go +++ b/defaults_windows.go @@ -52,7 +52,7 @@ func (m windowsmatcher) Match(p specs.Platform) bool { if match && m.OS == "windows" { // HPC containers do not have OS version filled - if p.OSVersion == "" { + if m.OSVersion == "" || p.OSVersion == "" { return true }