2020-02-22 23:31:31 +00:00
|
|
|
import { SinonStub, stub } from 'sinon';
|
2021-05-07 01:47:10 +00:00
|
|
|
import { expect } from 'chai';
|
|
|
|
|
2022-08-17 23:35:08 +00:00
|
|
|
import { spawnJournalctl } from '~/lib/journald';
|
2020-02-22 23:31:31 +00:00
|
|
|
|
2022-10-18 19:44:19 +00:00
|
|
|
describe('lib/journald', () => {
|
2020-02-22 23:31:31 +00:00
|
|
|
let spawn: SinonStub;
|
|
|
|
|
2020-05-15 11:01:51 +00:00
|
|
|
beforeEach((done) => {
|
2020-02-22 23:31:31 +00:00
|
|
|
spawn = stub(require('child_process'), 'spawn');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
2020-05-15 11:01:51 +00:00
|
|
|
afterEach((done) => {
|
2020-02-22 23:31:31 +00:00
|
|
|
spawn.restore();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
2022-10-18 19:44:19 +00:00
|
|
|
// TODO: this test is not really that useful as it basically is just testing
|
|
|
|
// the internal implementation of the method
|
2020-02-22 23:31:31 +00:00
|
|
|
it('spawnJournalctl calls spawn child process with expected args', () => {
|
|
|
|
spawnJournalctl({
|
|
|
|
all: true,
|
|
|
|
follow: true,
|
|
|
|
count: 10,
|
|
|
|
unit: 'nginx.service',
|
|
|
|
containerId: 'abc123',
|
|
|
|
format: 'json-pretty',
|
|
|
|
});
|
|
|
|
|
2022-12-05 19:24:11 +00:00
|
|
|
const expectedCommand = `journalctl`;
|
2020-02-22 23:31:31 +00:00
|
|
|
const expectedOptionalArgs = [
|
|
|
|
'-a',
|
|
|
|
'--follow',
|
|
|
|
'-u',
|
|
|
|
'nginx.service',
|
|
|
|
'-t',
|
|
|
|
'abc123',
|
|
|
|
'-n',
|
|
|
|
'10',
|
|
|
|
'-o',
|
|
|
|
'json-pretty',
|
|
|
|
];
|
|
|
|
|
|
|
|
const actualCommand = spawn.firstCall.args[0];
|
2022-12-05 19:24:11 +00:00
|
|
|
const actualOptionalArgs = spawn.firstCall.args[1];
|
2020-02-22 23:31:31 +00:00
|
|
|
|
|
|
|
expect(spawn.calledOnce).to.be.true;
|
|
|
|
|
|
|
|
expect(actualCommand).deep.equal(expectedCommand);
|
|
|
|
|
2020-05-15 11:01:51 +00:00
|
|
|
expectedOptionalArgs.forEach((arg) => {
|
2020-02-22 23:31:31 +00:00
|
|
|
expect(actualOptionalArgs).to.include(arg);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|