MonitoringSystemMemoryPluginTest.php in Monitoring 8
File
tests/src/Kernel/MonitoringSystemMemoryPluginTest.php
View source
<?php
namespace Drupal\Tests\monitoring\Kernel;
class MonitoringSystemMemoryPluginTest extends MonitoringUnitTestBase {
public function testSystemMemorySensorPlugin() {
$data = "MemTotal: 20000 kB\nMemAvailable: 10000 kB";
\Drupal::state()
->set('monitoring.test_meminfo', $data);
$sensor_manager = monitoring_sensor_manager();
$sensor_config = $sensor_manager
->getSensorConfigByName('system_memory');
$sensor_config
->set('status', TRUE);
$sensor_config
->save();
$sensor_result = $this
->runSensor('system_memory');
$this
->assertTrue($sensor_result
->isOk());
$this
->assertEquals($sensor_result
->getMessage(), '50 % free memory');
$this
->assertEquals($sensor_result
->getVerboseOutput()['memory_info']['#rows'][0]['type'], 'MemTotal');
$this
->assertEquals($sensor_result
->getVerboseOutput()['memory_info']['#rows'][0]['memory'], '20000 kB');
$data = 'No memory information provided.';
\Drupal::state()
->set('monitoring.test_meminfo', $data);
$sensor_result = $this
->runSensor('system_memory');
$this
->assertTrue($sensor_result
->isCritical());
$this
->assertEquals($sensor_result
->getMessage(), 'This sensor is not supported by your system. It is based on memory information from /proc/meminfo, only provided by UNIX-like systems.');
\Drupal::state()
->set('monitoring.test_meminfo', '');
$sensor_result = $this
->runSensor('system_memory');
$this
->assertTrue($sensor_result
->isCritical());
$this
->assertEquals($sensor_result
->getMessage(), 'This sensor is not supported by your system. It is based on memory information from /proc/meminfo, only provided by UNIX-like systems.');
$this
->assertNull($sensor_result
->getVerboseOutput());
}
}