tests: test each db schema file for proper format (#6580)

This commit is contained in:
Tony Murray
2017-05-04 15:14:14 -05:00
committed by Neil Lathwood
parent 422b2c8ae1
commit 6f99cb6d69
14 changed files with 53 additions and 25 deletions

View File

@@ -1 +1 @@
SELECT NOW()
SELECT NOW();

View File

@@ -1 +1 @@
ALTER TABLE `devices` ADD COLUMN `icon` VARCHAR(255) DEFAULT NULL
ALTER TABLE `devices` ADD COLUMN `icon` VARCHAR(255) DEFAULT NULL;

View File

@@ -1 +1 @@
UPDATE `sensors` SET sensor_limit=sensor_limit/1.3*1.8 WHERE sensor_class="fanspeed"
UPDATE `sensors` SET sensor_limit=sensor_limit/1.3*1.8 WHERE sensor_class='fanspeed';

View File

@@ -1 +1 @@
CREATE TABLE `alert_template_map` (`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,`alert_templates_id` INT NOT NULL ,`alert_rule_id` INT NOT NULL ,INDEX ( `alert_templates_id` , `alert_rule_id` )) ENGINE = INNODB
CREATE TABLE `alert_template_map` (`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,`alert_templates_id` INT NOT NULL ,`alert_rule_id` INT NOT NULL ,INDEX ( `alert_templates_id` , `alert_rule_id` )) ENGINE = INNODB;

View File

@@ -1 +1 @@
insert into `config` (`config_name`,`config_value`,`config_default`,`config_descr`,`config_group`,`config_group_order`,`config_sub_group`,`config_sub_group_order`,`config_hidden`,`config_disabled`) values ('alert.macros.rule.sensor','(%sensors.sensor_alert = 1)','(%sensors.sensor_alert = 1)','Sensors of interest','alerting',0,'macros',0,'1','0')
insert into `config` (`config_name`,`config_value`,`config_default`,`config_descr`,`config_group`,`config_group_order`,`config_sub_group`,`config_sub_group_order`,`config_hidden`,`config_disabled`) values ('alert.macros.rule.sensor','(%sensors.sensor_alert = 1)','(%sensors.sensor_alert = 1)','Sensors of interest','alerting',0,'macros',0,'1','0');

View File

@@ -1 +1 @@
ALTER TABLE `stp` CHANGE `timeSinceTopologyChange` `timeSinceTopologyChange` INT UNSIGNED NOT NULL
ALTER TABLE `stp` CHANGE `timeSinceTopologyChange` `timeSinceTopologyChange` INT UNSIGNED NOT NULL;

View File

@@ -1 +1 @@
INSERT INTO config (config_name,config_value,config_default,config_descr,config_group,config_group_order,config_sub_group,config_sub_group_order,config_hidden,config_disabled) values ('alert.transports.smseagle.url','','','SMSEagle API URL','alerting',0,'transports',0,'0','0'),('alert.transports.smseagle.user','','','SMSEagle User','alerting',0,'transports',0,'0','0'),('alert.transports.smseagle.token','','','SMSEagle Token','alerting',0,'transports',0,'0','0')
INSERT INTO config (config_name,config_value,config_default,config_descr,config_group,config_group_order,config_sub_group,config_sub_group_order,config_hidden,config_disabled) values ('alert.transports.smseagle.url','','','SMSEagle API URL','alerting',0,'transports',0,'0','0'),('alert.transports.smseagle.user','','','SMSEagle User','alerting',0,'transports',0,'0','0'),('alert.transports.smseagle.token','','','SMSEagle Token','alerting',0,'transports',0,'0','0');

View File

@@ -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();