mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
tests: test each db schema file for proper format (#6580)
This commit is contained in:
committed by
Neil Lathwood
parent
422b2c8ae1
commit
6f99cb6d69
@@ -39,6 +39,34 @@ class DBSetupTest extends DBTestCase
|
||||
}
|
||||
}
|
||||
|
||||
public function testSchemaFiles()
|
||||
{
|
||||
global $config;
|
||||
$files = glob($config['install_dir'].'/sql-schema/*.sql');
|
||||
|
||||
foreach ($files as $file) {
|
||||
$content = file_get_contents($file);
|
||||
|
||||
foreach (explode("\n", $content) as $line) {
|
||||
// skip comments and empty lines
|
||||
if (empty($line) || starts_with($line, array('#', '--'))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// each line must end with ;, prevents multiline and makes sql easy to run by hand
|
||||
// Warning may include whitespace such as space and \r
|
||||
if (!ends_with($line, ';')) {
|
||||
throw new PHPUnitException("Each line must end with a semicolin (;)\n$file: $line");
|
||||
}
|
||||
|
||||
// cannot assume user use the librenms database name
|
||||
if (str_contains($line, 'librenms')) {
|
||||
throw new PHPUnitException("Do not include the database name in schema files\n$file: $line");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function testSchema()
|
||||
{
|
||||
$schema = get_db_schema();
|
||||
|
Reference in New Issue
Block a user