diff --git a/src/database.js b/src/database.js index 00b76bac0..3e718d16a 100644 --- a/src/database.js +++ b/src/database.js @@ -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); } diff --git a/src/test/backuptask-test.js b/src/test/backuptask-test.js index efa81979f..888716efe 100644 --- a/src/test/backuptask-test.js +++ b/src/test/backuptask-test.js @@ -39,10 +39,6 @@ describe('backuptask', function () { await settings.setBackupConfig(backupConfig); }); - after(function () { - fs.rmSync(backupConfig.backupFolder, { recursive: true, force: true }); - }); - async function createBackup() { const taskId = await backups.startBackupTask({ username: 'test' }); @@ -76,7 +72,7 @@ describe('backuptask', function () { const result = await createBackup(); expect(fs.statSync(path.join(backupConfig.backupFolder, 'snapshot/box.tar.gz')).nlink).to.be(2); // hard linked to a rotated backup - expect(fs.statSync(path.join(backupConfig.backupFolder, `${result.id}.tar.gz`)).nlink).to.be(2); + expect(fs.statSync(path.join(backupConfig.backupFolder, `${result.remotePath}.tar.gz`)).nlink).to.be(2); backupInfo1 = result; }); @@ -90,8 +86,12 @@ describe('backuptask', function () { const result = await createBackup(); expect(fs.statSync(path.join(backupConfig.backupFolder, 'snapshot/box.tar.gz')).nlink).to.be(2); // hard linked to a rotated backup - expect(fs.statSync(path.join(backupConfig.backupFolder, `${result.id}.tar.gz`)).nlink).to.be(2); // hard linked to new backup - expect(fs.statSync(path.join(backupConfig.backupFolder, `${backupInfo1.id}.tar.gz`)).nlink).to.be(1); // not hard linked anymore + expect(fs.statSync(path.join(backupConfig.backupFolder, `${result.remotePath}.tar.gz`)).nlink).to.be(2); // hard linked to new backup + expect(fs.statSync(path.join(backupConfig.backupFolder, `${backupInfo1.remotePath}.tar.gz`)).nlink).to.be(1); // not hard linked anymore + }); + + it('cleanup', function () { + fs.rmSync(backupConfig.backupFolder, { recursive: true, force: true }); }); }); }); diff --git a/src/test/domains-test.js b/src/test/domains-test.js index 81504f238..57988a4c7 100644 --- a/src/test/domains-test.js +++ b/src/test/domains-test.js @@ -118,7 +118,7 @@ describe('Domains', function () { const [error] = await safe(domains.del(DOMAIN_0.domain, auditSource)); expect(error.reason).to.equal(BoxError.CONFLICT); - expect(error.message).to.contain('Domain is in use by one or more app'); + expect(error.message).to.contain('Domain is in use in an app\'s location'); await apps.del(appCopy.id); }); diff --git a/src/test/notifications-test.js b/src/test/notifications-test.js index c79061c82..8c5935aec 100644 --- a/src/test/notifications-test.js +++ b/src/test/notifications-test.js @@ -69,7 +69,7 @@ describe('Notifications', function () { }); it('cannot update non-existent notification', async function () { - const [error] = await safe(notifications.update({ id: 'random' }, { title: 'updated title 0', message: 'updated message 0', acknowledged: true })); + const [error] = await safe(notifications.update({ id: '1245' }, { title: 'updated title 0', message: 'updated message 0', acknowledged: true })); expect(error.reason).to.be(BoxError.NOT_FOUND); }); @@ -79,7 +79,7 @@ describe('Notifications', function () { }); it('cannot delete non-existent notification', async function () { - const [error] = await safe(notifications.del('random')); + const [error] = await safe(notifications.del('5213')); expect(error.reason).to.be(BoxError.NOT_FOUND); }); diff --git a/src/test/tasks-test.js b/src/test/tasks-test.js index a8fb0c338..edaeab6fd 100644 --- a/src/test/tasks-test.js +++ b/src/test/tasks-test.js @@ -78,7 +78,7 @@ describe('task', function () { }); it('del missing task fails', async function () { - const [error] = await safe(tasks._del('random')); + const [error] = await safe(tasks._del('1235')); expect(error.reason).to.be(BoxError.NOT_FOUND); });