shell: remove usage of .spawn
This commit is contained in:
@@ -11,74 +11,62 @@ const BoxError = require('../boxerror.js'),
|
||||
shell = require('../shell.js');
|
||||
|
||||
describe('shell', function () {
|
||||
it('can run valid program', function (done) {
|
||||
let cp = shell.spawn('test', 'ls', [ '-l' ], { }, function (error) {
|
||||
expect(cp).to.be.ok();
|
||||
expect(error).to.be(null);
|
||||
done();
|
||||
describe('execFile', function () {
|
||||
it('can run valid program', async function () {
|
||||
await shell.promises.execFile('test', 'ls', [ '-l' ], {});
|
||||
});
|
||||
|
||||
it('fails on invalid program', async function () {
|
||||
const [error] = await safe(shell.promises.execFile('test', 'randomprogram', [ ], {}));
|
||||
expect(error.reason).to.be(BoxError.SHELL_ERROR);
|
||||
});
|
||||
|
||||
it('fails on failing program', async function () {
|
||||
const [error] = await safe(shell.promises.execFile('test', '/usr/bin/false', [ ], {}));
|
||||
expect(error.reason).to.be(BoxError.SHELL_ERROR);
|
||||
});
|
||||
});
|
||||
|
||||
it('fails on invalid program', function (done) {
|
||||
shell.spawn('test', 'randomprogram', [ ], { }, function (error) {
|
||||
expect(error).to.be.ok();
|
||||
done();
|
||||
describe('sudo', function () {
|
||||
it('cannot sudo invalid program', function (done) {
|
||||
shell.sudo('test', [ 'randomprogram' ], {}, function (error) {
|
||||
expect(error).to.be.ok();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('can sudo valid program', function (done) {
|
||||
let RELOAD_NGINX_CMD = path.join(__dirname, '../src/scripts/restartservice.sh');
|
||||
shell.sudo('test', [ RELOAD_NGINX_CMD, 'nginx' ], {}, function (error) {
|
||||
expect(error).to.be.ok();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('can run valid program (promises)', async function () {
|
||||
let RELOAD_NGINX_CMD = path.join(__dirname, '../src/scripts/restartservice.sh');
|
||||
await safe(shell.promises.sudo('test', [ RELOAD_NGINX_CMD, 'nginx' ], {}));
|
||||
});
|
||||
});
|
||||
|
||||
it('fails on failing program', function (done) {
|
||||
shell.spawn('test', '/usr/bin/false', [ ], { }, function (error) {
|
||||
expect(error).to.be.ok();
|
||||
done();
|
||||
describe('exec', function () {
|
||||
it('exec a valid shell program', async function () {
|
||||
await shell.promises.exec('test', 'ls -l | wc -c', {});
|
||||
});
|
||||
});
|
||||
|
||||
it('cannot sudo invalid program', function (done) {
|
||||
shell.sudo('test', [ 'randomprogram' ], {}, function (error) {
|
||||
expect(error).to.be.ok();
|
||||
done();
|
||||
it('exec throws for invalid program', async function () {
|
||||
const [error] = await safe(shell.promises.exec('test', 'cannotexist', {}));
|
||||
expect(error.reason).to.be(BoxError.SHELL_ERROR);
|
||||
});
|
||||
});
|
||||
|
||||
it('can sudo valid program', function (done) {
|
||||
let RELOAD_NGINX_CMD = path.join(__dirname, '../src/scripts/restartservice.sh');
|
||||
shell.sudo('test', [ RELOAD_NGINX_CMD, 'nginx' ], {}, function (error) {
|
||||
expect(error).to.be.ok();
|
||||
done();
|
||||
it('exec throws for failed program', async function () {
|
||||
const [error] = await safe(shell.promises.exec('test', 'false', {}));
|
||||
expect(error.reason).to.be(BoxError.SHELL_ERROR);
|
||||
});
|
||||
});
|
||||
|
||||
it('can run valid program (promises)', async function () {
|
||||
let RELOAD_NGINX_CMD = path.join(__dirname, '../src/scripts/restartservice.sh');
|
||||
await safe(shell.promises.sudo('test', [ RELOAD_NGINX_CMD, 'nginx' ], {}));
|
||||
});
|
||||
|
||||
it('exec a valid shell program', function (done) {
|
||||
shell.exec('test', 'ls -l | wc -c', {}, function (error) {
|
||||
done(error);
|
||||
it('exec times out properly', async function () {
|
||||
const [error] = await safe(shell.promises.exec('sleeping', 'sleep 20', { timeout: 1000 }));
|
||||
expect(error.reason).to.be(BoxError.SHELL_ERROR);
|
||||
});
|
||||
});
|
||||
|
||||
it('exec a valid shell program (promises)', async function () {
|
||||
await shell.promises.exec('test', 'ls -l | wc -c', {});
|
||||
});
|
||||
|
||||
it('exec throws for invalid program', function (done) {
|
||||
shell.exec('test', 'cannotexist', {}, function (error) {
|
||||
expect(error).to.be.ok();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('exec throws for failed program', function (done) {
|
||||
shell.exec('test', 'false', {}, function (error) {
|
||||
expect(error).to.be.ok();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('exec times out properly', async function () {
|
||||
const [error] = await safe(shell.promises.exec('sleeping', 'sleep 20', { timeout: 1000 }));
|
||||
expect(error.reason).to.be(BoxError.SHELL_ERROR);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user