diff --git a/compare_test.go b/compare_test.go index 1968e51..a84e3e9 100644 --- a/compare_test.go +++ b/compare_test.go @@ -23,7 +23,7 @@ import ( ) func TestOnly(t *testing.T) { - for _, tc := range []struct { + for _, testcase := range []struct { platform string matches map[bool][]string }{ @@ -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 { @@ -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 }{ @@ -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 { @@ -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 }{ @@ -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 { @@ -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 @@ -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 { @@ -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 @@ -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) @@ -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 { diff --git a/cpuinfo_linux_test.go b/cpuinfo_linux_test.go index 59a8198..55e50c3 100644 --- a/cpuinfo_linux_test.go +++ b/cpuinfo_linux_test.go @@ -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) { diff --git a/platform_windows_compat.go b/platform_windows_compat.go index 4aa162a..bed579b 100644 --- a/platform_windows_compat.go +++ b/platform_windows_compat.go @@ -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 } @@ -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