shell: rewrite exec to use execFile

this also renames execFile to execArgs
This commit is contained in:
Girish Ramakrishnan
2024-02-21 18:37:10 +01:00
parent 14c9260ab0
commit cfd5c0f82b
6 changed files with 33 additions and 49 deletions

View File

@@ -11,18 +11,18 @@ const BoxError = require('../boxerror.js'),
shell = require('../shell.js');
describe('shell', function () {
describe('execFile', function () {
describe('execArgs', function () {
it('can run valid program', async function () {
await shell.promises.execFile('test', 'ls', [ '-l' ], {});
await shell.promises.execArgs('test', 'ls', [ '-l' ], {});
});
it('fails on invalid program', async function () {
const [error] = await safe(shell.promises.execFile('test', 'randomprogram', [ ], {}));
const [error] = await safe(shell.promises.execArgs('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', [ ], {}));
const [error] = await safe(shell.promises.execArgs('test', '/usr/bin/false', [ ], {}));
expect(error.reason).to.be(BoxError.SHELL_ERROR);
});
});
@@ -50,10 +50,6 @@ describe('shell', function () {
});
describe('exec', function () {
it('exec a valid shell program', async function () {
await shell.promises.exec('test', 'ls -l | wc -c', {});
});
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);
@@ -68,5 +64,14 @@ describe('shell', function () {
const [error] = await safe(shell.promises.exec('sleeping', 'sleep 20', { timeout: 1000 }));
expect(error.reason).to.be(BoxError.SHELL_ERROR);
});
it('cannot exec a shell program by default', async function () {
const [error] = await safe(shell.promises.exec('test', 'ls -l | wc -c', {}));
expect(error.reason).to.be(BoxError.SHELL_ERROR);
});
it('cannot exec a shell program b', async function () {
await shell.promises.exec('test', 'ls -l | wc -c', { shell: '/bin/bash' });
});
});
});