diff --git a/internal/overrides/overrides.go b/internal/overrides/overrides.go index 0ba130c..c5710b0 100644 --- a/internal/overrides/overrides.go +++ b/internal/overrides/overrides.go @@ -231,13 +231,11 @@ func ReleasePlatformSpecific(release int, info *distro.OSRelease) string { return fmt.Sprintf("alt%d", release) } - for _, v := range info.Like { - if v == "fedora" { - re := regexp.MustCompile(`platform:(\S+)`) - match := re.FindStringSubmatch(info.PlatformID) - if len(match) > 1 { - return fmt.Sprintf("%d.%s", release, match[0]) - } + if info.ID == "fedora" || slices.Contains(info.Like, "fedora") { + re := regexp.MustCompile(`platform:(\S+)`) + match := re.FindStringSubmatch(info.PlatformID) + if len(match) > 1 { + return fmt.Sprintf("%d.%s", release, match[1]) } } diff --git a/internal/overrides/overrides_test.go b/internal/overrides/overrides_test.go index f7be20e..0d51856 100644 --- a/internal/overrides/overrides_test.go +++ b/internal/overrides/overrides_test.go @@ -24,6 +24,7 @@ import ( "reflect" "testing" + "github.com/stretchr/testify/assert" "golang.org/x/text/language" "gitea.plemya-x.ru/Plemya-x/ALR/internal/overrides" @@ -195,3 +196,43 @@ func TestResolveLangs(t *testing.T) { t.Errorf("expected %v, got %v", expected, names) } } + +func TestReleasePlatformSpecific(t *testing.T) { + + type testCase struct { + info *distro.OSRelease + expected string + } + + for _, tc := range []testCase{ + { + info: &distro.OSRelease{ + ID: "centos", + Like: []string{"rhel", "fedora"}, + PlatformID: "platform:el8", + }, + expected: "1.el8", + }, + { + info: &distro.OSRelease{ + ID: "fedora", + PlatformID: "platform:f42", + }, + expected: "1.f42", + }, + { + info: &distro.OSRelease{ + ID: "altlinux", + }, + expected: "alt1", + }, + { + info: &distro.OSRelease{ + ID: "ubuntu", + }, + expected: "1", + }, + } { + assert.Equal(t, tc.expected, overrides.ReleasePlatformSpecific(1, tc.info)) + } +}