mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-03-21 03:25:46 +00:00
Add unit test to ensure journalctl process is spawned with expected
arguments. Signed-off-by: Ivan <ivan@mish.guru>
This commit is contained in:
parent
b5772740ae
commit
f5c51be07d
57
test/26-journald.spec.ts
Normal file
57
test/26-journald.spec.ts
Normal file
@ -0,0 +1,57 @@
|
||||
import { SinonStub, stub } from 'sinon';
|
||||
import constants = require('../src/lib/constants');
|
||||
import { spawnJournalctl } from '../src/lib/journald';
|
||||
import { expect } from './lib/chai-config';
|
||||
|
||||
describe('journald', () => {
|
||||
let spawn: SinonStub;
|
||||
|
||||
beforeEach(done => {
|
||||
spawn = stub(require('child_process'), 'spawn');
|
||||
done();
|
||||
});
|
||||
|
||||
afterEach(done => {
|
||||
spawn.restore();
|
||||
done();
|
||||
});
|
||||
|
||||
it('spawnJournalctl calls spawn child process with expected args', () => {
|
||||
spawnJournalctl({
|
||||
all: true,
|
||||
follow: true,
|
||||
count: 10,
|
||||
unit: 'nginx.service',
|
||||
containerId: 'abc123',
|
||||
format: 'json-pretty',
|
||||
});
|
||||
|
||||
const expectedCommand = `chroot`;
|
||||
const expectedCoreArgs = [`${constants.rootMountPoint}`, 'journalctl'];
|
||||
const expectedOptionalArgs = [
|
||||
'-a',
|
||||
'--follow',
|
||||
'-u',
|
||||
'nginx.service',
|
||||
'-t',
|
||||
'abc123',
|
||||
'-n',
|
||||
'10',
|
||||
'-o',
|
||||
'json-pretty',
|
||||
];
|
||||
|
||||
const actualCommand = spawn.firstCall.args[0];
|
||||
const actualCoreArgs = spawn.firstCall.args[1].slice(0, 2);
|
||||
const actualOptionalArgs = spawn.firstCall.args[1].slice(2);
|
||||
|
||||
expect(spawn.calledOnce).to.be.true;
|
||||
|
||||
expect(actualCommand).deep.equal(expectedCommand);
|
||||
expect(actualCoreArgs).deep.equal(expectedCoreArgs);
|
||||
|
||||
expectedOptionalArgs.forEach(arg => {
|
||||
expect(actualOptionalArgs).to.include(arg);
|
||||
});
|
||||
});
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user