apptask: asyncify
This commit is contained in:
@@ -10,6 +10,7 @@ const apptask = require('../apptask.js'),
|
||||
expect = require('expect.js'),
|
||||
fs = require('fs'),
|
||||
paths = require('../paths.js'),
|
||||
safe = require('safetydance'),
|
||||
_ = require('underscore');
|
||||
|
||||
describe('apptask', function () {
|
||||
@@ -18,70 +19,52 @@ describe('apptask', function () {
|
||||
before(setup);
|
||||
after(cleanup);
|
||||
|
||||
it('create volume', function (done) {
|
||||
apptask._createAppDir(app, function (error) {
|
||||
expect(fs.existsSync(paths.APPS_DATA_DIR + '/' + app.id)).to.be(true);
|
||||
expect(fs.existsSync(paths.APPS_DATA_DIR + '/' + app.id + '/data')).to.be(false);
|
||||
expect(error).to.be(null);
|
||||
done();
|
||||
});
|
||||
it('create volume', async function () {
|
||||
await apptask._createAppDir(app);
|
||||
expect(fs.existsSync(paths.APPS_DATA_DIR + '/' + app.id)).to.be(true);
|
||||
expect(fs.existsSync(paths.APPS_DATA_DIR + '/' + app.id + '/data')).to.be(false);
|
||||
});
|
||||
|
||||
it('delete volume - removeDirectory (false) ', function (done) {
|
||||
apptask._deleteAppDir(app, { removeDirectory: false }, function (error) {
|
||||
expect(fs.existsSync(paths.APPS_DATA_DIR + '/' + app.id)).to.be(true);
|
||||
expect(fs.readdirSync(paths.APPS_DATA_DIR + '/' + app.id).length).to.be(0); // empty
|
||||
expect(error).to.be(null);
|
||||
done();
|
||||
});
|
||||
it('delete volume - removeDirectory (false) ', async function () {
|
||||
await apptask._deleteAppDir(app, { removeDirectory: false });
|
||||
expect(fs.existsSync(paths.APPS_DATA_DIR + '/' + app.id)).to.be(true);
|
||||
expect(fs.readdirSync(paths.APPS_DATA_DIR + '/' + app.id).length).to.be(0); // empty
|
||||
});
|
||||
|
||||
it('delete volume - removeDirectory (true) ', function (done) {
|
||||
apptask._deleteAppDir(app, { removeDirectory: true }, function (error) {
|
||||
expect(!fs.existsSync(paths.APPS_DATA_DIR + '/' + app.id)).to.be(true);
|
||||
expect(error).to.be(null);
|
||||
done();
|
||||
});
|
||||
it('delete volume - removeDirectory (true) ', async function () {
|
||||
await apptask._deleteAppDir(app, { removeDirectory: true });
|
||||
expect(!fs.existsSync(paths.APPS_DATA_DIR + '/' + app.id)).to.be(true);
|
||||
});
|
||||
|
||||
it('barfs on empty manifest', function (done) {
|
||||
var badApp = _.extend({ }, app);
|
||||
it('barfs on empty manifest', async function () {
|
||||
const badApp = _.extend({ }, app);
|
||||
badApp.manifest = { };
|
||||
|
||||
apptask._verifyManifest(badApp.manifest, function (error) {
|
||||
expect(error).to.be.ok();
|
||||
done();
|
||||
});
|
||||
const [error] = await safe(apptask._verifyManifest(badApp.manifest));
|
||||
expect(error).to.be.ok();
|
||||
});
|
||||
|
||||
it('fails on bad manifest', function (done) {
|
||||
var badApp = _.extend({ }, app);
|
||||
it('fails on bad manifest', async function () {
|
||||
const badApp = _.extend({ }, app);
|
||||
badApp.manifest = _.extend({ }, app.manifest);
|
||||
delete badApp.manifest.httpPort;
|
||||
|
||||
apptask._verifyManifest(badApp.manifest, function (error) {
|
||||
expect(error).to.be.ok();
|
||||
done();
|
||||
});
|
||||
const [error] = await safe(apptask._verifyManifest(badApp.manifest));
|
||||
expect(error).to.be.ok();
|
||||
});
|
||||
|
||||
it('barfs on incompatible manifest', function (done) {
|
||||
var badApp = _.extend({ }, app);
|
||||
it('barfs on incompatible manifest', async function () {
|
||||
const badApp = _.extend({ }, app);
|
||||
badApp.manifest = _.extend({ }, app.manifest);
|
||||
badApp.manifest.maxBoxVersion = '0.0.0'; // max box version is too small
|
||||
|
||||
apptask._verifyManifest(badApp.manifest, function (error) {
|
||||
expect(error).to.be.ok();
|
||||
done();
|
||||
});
|
||||
const [error] = await safe(apptask._verifyManifest(badApp.manifest));
|
||||
expect(error).to.be.ok();
|
||||
});
|
||||
|
||||
it('verifies manifest', function (done) {
|
||||
var goodApp = _.extend({ }, app);
|
||||
it('verifies manifest', async function () {
|
||||
const goodApp = _.extend({ }, app);
|
||||
|
||||
apptask._verifyManifest(goodApp.manifest, function (error) {
|
||||
expect(error).to.be(null);
|
||||
done();
|
||||
});
|
||||
await apptask._verifyManifest(goodApp.manifest);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -5,7 +5,9 @@
|
||||
'use strict';
|
||||
|
||||
const database = require('../database'),
|
||||
expect = require('expect.js');
|
||||
expect = require('expect.js'),
|
||||
fs = require('fs'),
|
||||
safe = require('safetydance');
|
||||
|
||||
describe('database', function () {
|
||||
describe('init', function () {
|
||||
@@ -28,32 +30,23 @@ describe('database', function () {
|
||||
await database._clear();
|
||||
});
|
||||
|
||||
it('cannot import from non-existent file', function (done) {
|
||||
database.importFromFile('/does/not/exist', function (error) {
|
||||
expect(error).to.be.ok();
|
||||
done();
|
||||
});
|
||||
it('cannot import from non-existent file', async function () {
|
||||
const [error] = await safe(database.importFromFile('/does/not/exist'));
|
||||
expect(error).to.be.ok();
|
||||
});
|
||||
|
||||
it('can export to file', function (done) {
|
||||
it('can export to file', async function () {
|
||||
// arch only has maria db which lacks some mysqldump options we need, this is only here to allow running the tests :-/
|
||||
if (require('child_process').execSync('/usr/bin/mysqldump --version').toString().indexOf('MariaDB') !== -1) return done();
|
||||
if (!fs.readFileSync('/etc/lsb-release', 'utf8').includes('Ubuntu')) return;
|
||||
|
||||
database.exportToFile('/tmp/box.mysqldump', function (error) {
|
||||
expect(error).to.be(null);
|
||||
done();
|
||||
});
|
||||
await database.exportToFile('/tmp/box.mysqldump');
|
||||
});
|
||||
|
||||
it('can import from file', function (done) {
|
||||
it('can import from file', async function () {
|
||||
// arch only has maria db which lacks some mysqldump options we need, this is only here to allow running the tests :-/
|
||||
if (require('child_process').execSync('/usr/bin/mysqldump --version').toString().indexOf('MariaDB') !== -1) return done();
|
||||
if (!fs.readFileSync('/etc/lsb-release', 'utf8').includes('Ubuntu')) return;
|
||||
|
||||
database.importFromFile('/tmp/box.mysqldump', function (error) {
|
||||
expect(error).to.be(null);
|
||||
done();
|
||||
});
|
||||
await database.importFromFile('/tmp/box.mysqldump');
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user