tests: add tests for ReleasePlatformSpecific
This commit is contained in:
parent
981f49587b
commit
3deb6c9455
@ -231,13 +231,11 @@ func ReleasePlatformSpecific(release int, info *distro.OSRelease) string {
|
|||||||
return fmt.Sprintf("alt%d", release)
|
return fmt.Sprintf("alt%d", release)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, v := range info.Like {
|
if info.ID == "fedora" || slices.Contains(info.Like, "fedora") {
|
||||||
if v == "fedora" {
|
re := regexp.MustCompile(`platform:(\S+)`)
|
||||||
re := regexp.MustCompile(`platform:(\S+)`)
|
match := re.FindStringSubmatch(info.PlatformID)
|
||||||
match := re.FindStringSubmatch(info.PlatformID)
|
if len(match) > 1 {
|
||||||
if len(match) > 1 {
|
return fmt.Sprintf("%d.%s", release, match[1])
|
||||||
return fmt.Sprintf("%d.%s", release, match[0])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
"golang.org/x/text/language"
|
"golang.org/x/text/language"
|
||||||
|
|
||||||
"gitea.plemya-x.ru/Plemya-x/ALR/internal/overrides"
|
"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)
|
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))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user