shell: rework code to use shell.spawn
spawn gives out streams and we have more control over the stdout/stderr buffers. otherwise, we have to provide a max buffer capture size to exec
This commit is contained in:
@@ -11,18 +11,18 @@ const BoxError = require('../boxerror.js'),
|
||||
shell = require('../shell.js')('test');
|
||||
|
||||
describe('shell', function () {
|
||||
describe('execArgs', function () {
|
||||
describe('spawn', function () {
|
||||
it('can run valid program', async function () {
|
||||
await shell.execArgs('ls', [ '-l' ], {});
|
||||
await shell.spawn('ls', [ '-l' ], {});
|
||||
});
|
||||
|
||||
it('fails on invalid program', async function () {
|
||||
const [error] = await safe(shell.execArgs('randomprogram', [ ], {}));
|
||||
const [error] = await safe(shell.spawn('randomprogram', [], {}));
|
||||
expect(error.reason).to.be(BoxError.SHELL_ERROR);
|
||||
});
|
||||
|
||||
it('fails on failing program', async function () {
|
||||
const [error] = await safe(shell.execArgs('/usr/bin/false', [ ], {}));
|
||||
const [error] = await safe(shell.spawn('/usr/bin/false', [], {}));
|
||||
expect(error.reason).to.be(BoxError.SHELL_ERROR);
|
||||
});
|
||||
});
|
||||
@@ -49,19 +49,19 @@ describe('shell', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('exec', function () {
|
||||
it('exec throws for invalid program', async function () {
|
||||
const [error] = await safe(shell.exec('cannotexist', {}));
|
||||
describe('spawn', function () {
|
||||
it('spawn throws for invalid program', async function () {
|
||||
const [error] = await safe(shell.spawn('cannotexist', [], {}));
|
||||
expect(error.reason).to.be(BoxError.SHELL_ERROR);
|
||||
});
|
||||
|
||||
it('exec throws for failed program', async function () {
|
||||
const [error] = await safe(shell.exec('false', {}));
|
||||
it('spawn throws for failed program', async function () {
|
||||
const [error] = await safe(shell.spawn('false', [], {}));
|
||||
expect(error.reason).to.be(BoxError.SHELL_ERROR);
|
||||
});
|
||||
|
||||
it('exec times out properly', async function () {
|
||||
const [error] = await safe(shell.exec('sleep 20', { timeout: 1000 }));
|
||||
it('spawn times out properly', async function () {
|
||||
const [error] = await safe(shell.spawn('sleep', ['20'], { timeout: 1000 }));
|
||||
expect(error.reason).to.be(BoxError.SHELL_ERROR);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user