Skip to content

Commit 0766df4

Browse files
authored
Add tests for more operating systems (almalinux, openEuler, rocky) (#143)
* Add test for AlmaLinux 9 The regex pattern to match the "codename" needed to be amended to allow spaces. * Add test for openEuler 20.03 I had to amend the regex to allow dashes in the codename. Used `docker pull openeuler/openeuler:20.03` for test data. Fixes #142 * Add test case for Rocky Linux 9 Fixes #130 * Add changelog
1 parent 2f6a5ef commit 0766df4

File tree

16 files changed

+110
-4
lines changed

16 files changed

+110
-4
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12-
- Replace pkg/errors with Go 1.13 native errors #123.
12+
- Replace pkg/errors with Go 1.13 native errors. [#123](https://github.com/elastic/go-sysinfo/pull/123)
13+
- Add OS family mappings for `rocky`, `openEuler`, and `almalinux`. [#143](https://github.com/elastic/go-sysinfo/pull/143)
1314

1415
### Changed
1516

16-
- Remove custom sysctl implementation and partial cgo requirement
17+
- Remove custom sysctl implementation and partial cgo requirement. [#135](https://github.com/elastic/go-sysinfo/pull/135)
1718
- Changes on the `Host` and `LoadAverage` interfaces, now implemented by default on Linux and Darwin platforms. [#140](https://github.com/elastic/go-sysinfo/pull/140)
1819

1920
### Deprecated

providers/linux/os.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const (
3737
osRelease = "/etc/os-release"
3838
lsbRelease = "/etc/lsb-release"
3939
distribRelease = "/etc/*-release"
40-
versionGrok = `(?P<version>(?P<major>[0-9]+)\.?(?P<minor>[0-9]+)?\.?(?P<patch>\w+)?)(?: \((?P<codename>\w+)\))?`
40+
versionGrok = `(?P<version>(?P<major>[0-9]+)\.?(?P<minor>[0-9]+)?\.?(?P<patch>\w+)?)(?: \((?P<codename>[-\w ]+)\))?`
4141
)
4242

4343
var (
@@ -50,7 +50,8 @@ var (
5050

5151
// familyMap contains a mapping of family -> []platforms.
5252
var familyMap = map[string][]string{
53-
"redhat": {"redhat", "fedora", "centos", "scientific", "oraclelinux", "ol", "amzn", "rhel"},
53+
"redhat": {"redhat", "fedora", "centos", "scientific", "oraclelinux", "ol",
54+
"amzn", "rhel", "almalinux", "openeuler", "rocky"},
5455
"debian": {"debian", "ubuntu", "raspbian", "linuxmint"},
5556
"suse": {"suse", "sles", "opensuse"},
5657
}

providers/linux/os_test.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,24 @@ import (
2929
)
3030

3131
func TestOperatingSystem(t *testing.T) {
32+
t.Run("almalinux9", func(t *testing.T) {
33+
// Data from 'docker pull almalinux:9'.
34+
os, err := getOSInfo("testdata/almalinux9")
35+
if err != nil {
36+
t.Fatal(err)
37+
}
38+
assert.Equal(t, types.OSInfo{
39+
Type: "linux",
40+
Family: "redhat",
41+
Platform: "almalinux",
42+
Name: "AlmaLinux",
43+
Version: "9.1 (Lime Lynx)",
44+
Major: 9,
45+
Minor: 1,
46+
Codename: "Lime Lynx",
47+
}, *os)
48+
t.Logf("%#v", os)
49+
})
3250
t.Run("amazon2017.03", func(t *testing.T) {
3351
os, err := getOSInfo("testdata/amazon2017.03")
3452
if err != nil {
@@ -182,6 +200,41 @@ func TestOperatingSystem(t *testing.T) {
182200
}, *os)
183201
t.Logf("%#v", os)
184202
})
203+
t.Run("rockylinux9", func(t *testing.T) {
204+
// Data from 'docker pull rockylinux:9.0'.
205+
os, err := getOSInfo("testdata/rockylinux9")
206+
if err != nil {
207+
t.Fatal(err)
208+
}
209+
assert.Equal(t, types.OSInfo{
210+
Type: "linux",
211+
Family: "redhat",
212+
Platform: "rocky",
213+
Name: "Rocky Linux",
214+
Version: "9.0 (Blue Onyx)",
215+
Major: 9,
216+
Minor: 0,
217+
Codename: "Blue Onyx",
218+
}, *os)
219+
t.Logf("%#v", os)
220+
})
221+
t.Run("openeuler20.03", func(t *testing.T) {
222+
os, err := getOSInfo("testdata/openeuler20.03")
223+
if err != nil {
224+
t.Fatal(err)
225+
}
226+
assert.Equal(t, types.OSInfo{
227+
Type: "linux",
228+
Family: "redhat",
229+
Platform: "openEuler",
230+
Name: "openEuler",
231+
Version: "20.03 (LTS-SP3)",
232+
Major: 20,
233+
Minor: 3,
234+
Codename: "LTS-SP3",
235+
}, *os)
236+
t.Logf("%#v", os)
237+
})
185238
t.Run("oraclelinux7", func(t *testing.T) {
186239
os, err := getOSInfo("testdata/oraclelinux7")
187240
if err != nil {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
AlmaLinux release 9.1 (Lime Lynx)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../usr/lib/os-release
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
almalinux-release
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
almalinux-release
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
NAME="AlmaLinux"
2+
VERSION="9.1 (Lime Lynx)"
3+
ID="almalinux"
4+
ID_LIKE="rhel centos fedora"
5+
VERSION_ID="9.1"
6+
PLATFORM_ID="platform:el9"
7+
PRETTY_NAME="AlmaLinux 9.1 (Lime Lynx)"
8+
ANSI_COLOR="0;34"
9+
LOGO="fedora-logo-icon"
10+
CPE_NAME="cpe:/o:almalinux:almalinux:9::baseos"
11+
HOME_URL="https://almalinux.org/"
12+
DOCUMENTATION_URL="https://wiki.almalinux.org/"
13+
BUG_REPORT_URL="https://bugs.almalinux.org/"
14+
15+
ALMALINUX_MANTISBT_PROJECT="AlmaLinux-9"
16+
ALMALINUX_MANTISBT_PROJECT_VERSION="9.1"
17+
REDHAT_SUPPORT_PRODUCT="AlmaLinux"
18+
REDHAT_SUPPORT_PRODUCT_VERSION="9.1"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
openEuler release 20.03 (LTS-SP3)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
NAME="openEuler"
2+
VERSION="20.03 (LTS-SP3)"
3+
ID="openEuler"
4+
VERSION_ID="20.03"
5+
PRETTY_NAME="openEuler 20.03 (LTS-SP3)"
6+
ANSI_COLOR="0;31"
7+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
openEuler-release
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../usr/lib/os-release
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rocky-release
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Rocky Linux release 9.0 (Blue Onyx)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rocky-release
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
NAME="Rocky Linux"
2+
VERSION="9.0 (Blue Onyx)"
3+
ID="rocky"
4+
ID_LIKE="rhel centos fedora"
5+
VERSION_ID="9.0"
6+
PLATFORM_ID="platform:el9"
7+
PRETTY_NAME="Rocky Linux 9.0 (Blue Onyx)"
8+
ANSI_COLOR="0;32"
9+
LOGO="fedora-logo-icon"
10+
CPE_NAME="cpe:/o:rocky:rocky:9::baseos"
11+
HOME_URL="https://rockylinux.org/"
12+
BUG_REPORT_URL="https://bugs.rockylinux.org/"
13+
ROCKY_SUPPORT_PRODUCT="Rocky-Linux-9"
14+
ROCKY_SUPPORT_PRODUCT_VERSION="9.0"
15+
REDHAT_SUPPORT_PRODUCT="Rocky Linux"
16+
REDHAT_SUPPORT_PRODUCT_VERSION="9.0"

0 commit comments

Comments
 (0)