Skip to content

Commit 7da247b

Browse files
test: ensure language does not affect cpu_load_average #716
1 parent 1d96e27 commit 7da247b

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Tests/APIModelsSystemStatusTestCase.inc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace RESTAPI\Tests;
44

55
use RESTAPI\Core\Command;
6+
use RESTAPI\Core\Model;
67
use RESTAPI\Core\TestCase;
78
use RESTAPI\Models\SystemStatus;
89

@@ -44,4 +45,33 @@ class APIModelsSystemStatusTestCase extends TestCase {
4445
(new Command(command: '/bin/kenv -q smbios.bios.reldate 2>/dev/null', trim_whitespace: true))->output,
4546
);
4647
}
48+
49+
/**
50+
* Checks that the load average can can be read correctly despite the system's assign language. Normally,
51+
* the load average format can change based on the systems assigned language and cause issues parsing the
52+
* value into an array. This is a regression test for #716.
53+
*/
54+
public function test_language_does_not_change_cpu_load_avg(): void {
55+
# Change the language to German
56+
Model::set_config("system/language", "de_DE");
57+
set_language();
58+
59+
# Ensure we can read the SystemStatus cpu_load_average without an error
60+
$this->assert_does_not_throw(
61+
callable: function () {
62+
$system_status = new SystemStatus();
63+
$this->assert_equals(count($system_status->cpu_load_avg->value), 3);
64+
}
65+
);
66+
67+
# Reset the language to English and check again
68+
Model::set_config("system/language", "en_US");
69+
set_language();
70+
$this->assert_does_not_throw(
71+
callable: function () {
72+
$system_status = new SystemStatus();
73+
$this->assert_equals(count($system_status->cpu_load_avg->value), 3);
74+
}
75+
);
76+
}
4777
}

0 commit comments

Comments
 (0)