Skip to content

Commit 2b94fb1

Browse files
committed
Added tests for os_version_minor
Signed-off-by: Victor Moene <[email protected]>
1 parent 4d08ba8 commit 2b94fb1

File tree

2 files changed

+114
-0
lines changed

2 files changed

+114
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
body common control
2+
{
3+
bundlesequence => { "test", "check" };
4+
}
5+
6+
bundle agent test
7+
{
8+
9+
vars:
10+
# Platforms to test
11+
any::
12+
"platforms"
13+
slist => { "debian", "ubuntu", "redhat", "rhel", "centos", "fedora",
14+
"aix", "hpux", "suse", "opensuse", "opensuse_leap", "sles",
15+
"solaris", "sunos", "windows", "freebsd", "macos" };
16+
17+
18+
# Regex matching current platforms OS-class with version numbers
19+
!solaris&!sunos::
20+
"class_regex"
21+
string => format("^(%s)_[0-9]+_[0-9]+$", join("|", "platforms"));
22+
solaris|sunos::
23+
"class_regex"
24+
string => format("^(%s)_[0-9]+$", join("|", "platforms"));
25+
26+
# Regex to extract minor version number from OS-class
27+
# Edge cases:
28+
# - On Solaris/SunOS minor version comes second
29+
# E.g. Solaris 11 has class "solaris_5_11"
30+
any::
31+
"extract_regex"
32+
string => ifelse("solaris|sunos", "^[a-z]+_([0-9]+)$",
33+
"opensuse_leap", "^[a-z_]+_[0-9]+_([0-9]+$)",
34+
"^[a-z]+_[0-9]+_([0-9]+$)");
35+
36+
# Find OS-class with version numbers using regex
37+
any::
38+
"os_class"
39+
string => nth(classesmatching("$(class_regex)"), "0");
40+
41+
# Get extracted minor version number
42+
any::
43+
"expected"
44+
string => nth("version_number", "1");
45+
46+
classes:
47+
any::
48+
"regextract_success"
49+
expression => regextract("$(extract_regex)", "$(os_class)", "version_number");
50+
}
51+
52+
bundle agent check
53+
{
54+
vars:
55+
any::
56+
"defined_classes"
57+
slist => classesmatching(".*");
58+
59+
classes:
60+
any::
61+
"passed"
62+
expression => strcmp("$(test.expected)", "$(sys.os_version_minor)");
63+
64+
reports:
65+
DEBUG::
66+
"Version number extracted from class: $(test.os_class)";
67+
"Defined classes: $(defined_classes)";
68+
"$(this.promise_filename) Expected: $(test.expected)";
69+
"$(this.promise_filename) Found: $(sys.os_version_minor)";
70+
passed::
71+
"$(this.promise_filename) Pass";
72+
!passed::
73+
"$(this.promise_filename) FAIL";
74+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
body common control
2+
{
3+
bundlesequence => { "check" };
4+
}
5+
6+
bundle agent check
7+
{
8+
classes:
9+
ubuntu_20_04|ubuntu_22_04|ubuntu_24_04::
10+
"ok"
11+
if => strcmp("$(sys.os_version_minor)", "04");
12+
"not_ok"
13+
if => not(strcmp("$(sys.os_version_minor)", "04"));
14+
15+
debian_12_11::
16+
"ok"
17+
if => strcmp("$(sys.os_version_minor)", "11");
18+
"not_ok"
19+
if => not(strcmp("$(sys.os_version_minor)", "11"));
20+
21+
centos_7_6::
22+
"ok"
23+
if => strcmp("$(sys.os_version_minor)", "6");
24+
"not_ok"
25+
if => not(strcmp("$(sys.os_version_minor)", "6"));
26+
27+
redhat_8_10::
28+
"ok"
29+
if => strcmp("$(sys.os_version_minor)", "10");
30+
"not_ok"
31+
if => not(strcmp("$(sys.os_version_minor)", "10"));
32+
33+
reports:
34+
DEBUG::
35+
"$(sys.os_name_human)_$(sys.os_version_major)_$(sys.os_version_minor)";
36+
ok.!not_ok::
37+
"$(this.promise_filename) Pass";
38+
!ok|not_ok::
39+
"$(this.promise_filename) FAIL";
40+
}

0 commit comments

Comments
 (0)