Fix tests

This commit is contained in:
Girish Ramakrishnan
2023-07-11 16:32:28 +05:30
parent 2d4e7c9c0a
commit 5beb7d7d92
5 changed files with 15 additions and 16 deletions

View File

@@ -17,10 +17,10 @@ const assert = require('assert'),
BoxError = require('./boxerror.js'),
constants = require('./constants.js'),
debug = require('debug')('box:database'),
fs = require('fs'),
mysql = require('mysql'),
safe = require('safetydance'),
shell = require('./shell.js'),
util = require('util');
shell = require('./shell.js');
let gConnectionPool = null;
@@ -75,10 +75,9 @@ async function uninitialize() {
}
async function clear() {
const cmd = util.format('mysql --host="%s" --user="%s" --password="%s" -Nse "SHOW TABLES" %s | grep -v "^migrations$" | while read table; do mysql --host="%s" --user="%s" --password="%s" -e "SET FOREIGN_KEY_CHECKS = 0; TRUNCATE TABLE $table" %s; done',
gDatabase.hostname, gDatabase.username, gDatabase.password, gDatabase.name,
gDatabase.hostname, gDatabase.username, gDatabase.password, gDatabase.name);
await fs.promises.writeFile('/tmp/extra.cnf', `[client]\nhost=${gDatabase.hostname}\nuser=${gDatabase.username}\npassword=${gDatabase.password}\ndatabase=${gDatabase.name}`, 'utf8');
const cmd = 'mysql --defaults-extra-file=/tmp/extra.cnf -Nse "SHOW TABLES" | grep -v "^migrations$" | while read table; do mysql --defaults-extra-file=/tmp/extra.cnf -e "SET FOREIGN_KEY_CHECKS = 0; TRUNCATE TABLE $table"; done';
await shell.promises.exec('clear_database', cmd);
}