|
3 | 3 | namespace RESTAPI\Tests; |
4 | 4 |
|
5 | 5 | use RESTAPI\Core\Command; |
| 6 | +use RESTAPI\Core\Model; |
6 | 7 | use RESTAPI\Core\TestCase; |
7 | 8 | use RESTAPI\Models\SystemStatus; |
8 | 9 |
|
@@ -44,4 +45,33 @@ class APIModelsSystemStatusTestCase extends TestCase { |
44 | 45 | (new Command(command: '/bin/kenv -q smbios.bios.reldate 2>/dev/null', trim_whitespace: true))->output, |
45 | 46 | ); |
46 | 47 | } |
| 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 | + } |
47 | 77 | } |
0 commit comments