Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions compare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
)

func TestOnly(t *testing.T) {
for _, tc := range []struct {
for _, testcase := range []struct {
platform string
matches map[bool][]string
}{
Expand Down Expand Up @@ -299,7 +299,6 @@ func TestOnly(t *testing.T) {
},
},
} {
testcase := tc
t.Run(testcase.platform, func(t *testing.T) {
p, err := Parse(testcase.platform)
if err != nil {
Expand All @@ -322,7 +321,7 @@ func TestOnly(t *testing.T) {
}

func TestOnlyStrict(t *testing.T) {
for _, tc := range []struct {
for _, testcase := range []struct {
platform string
matches map[bool][]string
}{
Expand Down Expand Up @@ -573,7 +572,6 @@ func TestOnlyStrict(t *testing.T) {
},
},
} {
testcase := tc
t.Run(testcase.platform, func(t *testing.T) {
p, err := Parse(testcase.platform)
if err != nil {
Expand All @@ -596,7 +594,7 @@ func TestOnlyStrict(t *testing.T) {
}

func TestOnlyOS(t *testing.T) {
for _, tc := range []struct {
for _, testcase := range []struct {
platform string
matches map[bool][]string
}{
Expand Down Expand Up @@ -643,7 +641,6 @@ func TestOnlyOS(t *testing.T) {
},
},
} {
testcase := tc
t.Run(testcase.platform, func(t *testing.T) {
p, err := Parse(testcase.platform)
if err != nil {
Expand All @@ -666,7 +663,7 @@ func TestOnlyOS(t *testing.T) {
}

func TestOnlyOSLess(t *testing.T) {
for _, tc := range []struct {
for _, testcase := range []struct {
platform string
platforms []string
expected []string
Expand All @@ -690,7 +687,6 @@ func TestOnlyOSLess(t *testing.T) {
expected: []string{"linux/amd64", "linux/arm64", "windows/amd64", "darwin/amd64"},
},
} {
testcase := tc
t.Run(testcase.platform, func(t *testing.T) {
p, err := Parse(testcase.platform)
if err != nil {
Expand All @@ -716,7 +712,7 @@ func TestOnlyOSLess(t *testing.T) {
}

func TestCompareOSFeatures(t *testing.T) {
for _, tc := range []struct {
for _, testcase := range []struct {
platform string
platforms []string
expected []string
Expand Down Expand Up @@ -753,7 +749,6 @@ func TestCompareOSFeatures(t *testing.T) {
[]string{"linux(+other)/amd64", "linux(7.2+other)/amd64", "linux/amd64", "linux(7.1)/amd64"},
},
} {
testcase := tc
t.Run(testcase.platform, func(t *testing.T) {
t.Parallel()
p, err := Parse(testcase.platform)
Expand Down Expand Up @@ -783,7 +778,6 @@ func TestCompareOSFeatures(t *testing.T) {
},
} {
mc := stc.mc
testcase := testcase
t.Run(stc.name, func(t *testing.T) {
p, err := ParseAll(testcase.platforms)
if err != nil {
Expand Down
7 changes: 3 additions & 4 deletions cpuinfo_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,9 @@ func TestGetCPUVariantFromArch(t *testing.T) {
if err == nil {
if testcase.expectedErr != nil {
t.Fatalf("Expect to get error: %v, however no error got", testcase.expectedErr)
} else {
if variant != testcase.output {
t.Fatalf("Expect to get variant: %v, however %v returned", testcase.output, variant)
}
}
if variant != testcase.output {
t.Fatalf("Expect to get variant: %v, however %v returned", testcase.output, variant)
}
} else {
if !errors.Is(err, testcase.expectedErr) {
Expand Down
18 changes: 7 additions & 11 deletions platform_windows_compat.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func checkWindowsHostAndContainerCompat(host, ctr windowsOSVersion) bool {
return false
}

// If host is < WS 2022, exact version match is required
// Before WS2022, exact build matching is required.
if host.Build < ltsc2022 {
return host.Build == ctr.Build
}
Expand All @@ -91,20 +91,16 @@ func checkWindowsHostAndContainerCompat(host, ctr windowsOSVersion) bool {
// ABI policy, every host from LTSC N up to (but not including) LTSC N+1 can
// run containers from LTSC N-1 up to the host build.
//
// So we find the largest LTSC <= host.Build, then step one entry back to
// Find the largest LTSC <= host.Build, then step one entry back to
// get the floor. If host.Build is past the latest LTSC in the list
// (e.g. a 26200 host, which is in the WS2025 generation), the floor is
// still the previous LTSC (20348), not the latest LTSC itself.
//
// If host is the very first LTSC (or no entry matches, which is impossible
// here since we already checked host.Build >= ltsc2022), use that LTSC as
// the floor.
var supportedLTSCRelease uint16 = ltsc2022
for i := len(compatLTSCReleases) - 1; i >= 0; i-- {
if host.Build >= compatLTSCReleases[i] {
if i == 0 {
supportedLTSCRelease = compatLTSCReleases[i]
} else {
// Default to the first LTSC when the matching release has no predecessor.
supportedLTSCRelease := compatLTSCReleases[0]
for i, release := range slices.Backward(compatLTSCReleases) {
if host.Build >= release {
if i > 0 {
supportedLTSCRelease = compatLTSCReleases[i-1]
}
break
Expand Down
Loading