2024-02-29 19:00:39 -03:00
|
|
|
import type { SinonStub } from 'sinon';
|
|
|
|
import { stub } from 'sinon';
|
2021-05-07 01:47:10 +00:00
|
|
|
import { expect } from 'chai';
|
2024-03-05 15:15:30 -03:00
|
|
|
import childProcess from 'child_process';
|
2021-05-07 01:47:10 +00:00
|
|
|
|
2022-08-17 19:35:08 -04:00
|
|
|
import { spawnJournalctl } from '~/lib/journald';
|
2020-02-22 16:31:31 -07:00
|
|
|
|
2022-10-18 16:44:19 -03:00
|
|
|
describe('lib/journald', () => {
|
2020-02-22 16:31:31 -07:00
|
|
|
let spawn: SinonStub;
|
|
|
|
|
2020-05-15 12:01:51 +01:00
|
|
|
beforeEach((done) => {
|
2024-02-29 19:00:39 -03:00
|
|
|
spawn = stub(childProcess, 'spawn');
|
2020-02-22 16:31:31 -07:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
2020-05-15 12:01:51 +01:00
|
|
|
afterEach((done) => {
|
2020-02-22 16:31:31 -07:00
|
|
|
spawn.restore();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
2022-10-18 16:44:19 -03:00
|
|
|
// TODO: this test is not really that useful as it basically is just testing
|
|
|
|
// the internal implementation of the method
|
2020-02-22 16:31:31 -07: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-27 08:30:21 +01:00
|
|
|
since: '2014-03-25 03:59:56.654563',
|
|
|
|
until: '2014-03-25 03:59:59.654563',
|
2020-02-22 16:31:31 -07:00
|
|
|
});
|
|
|
|
|
2022-12-05 16:24:11 -03:00
|
|
|
const expectedCommand = `journalctl`;
|
2020-02-22 16:31:31 -07:00
|
|
|
const expectedOptionalArgs = [
|
|
|
|
'-a',
|
|
|
|
'--follow',
|
|
|
|
'-u',
|
|
|
|
'nginx.service',
|
|
|
|
'-t',
|
|
|
|
'abc123',
|
|
|
|
'-n',
|
|
|
|
'10',
|
|
|
|
'-o',
|
|
|
|
'json-pretty',
|
2022-12-27 08:30:21 +01:00
|
|
|
'-S',
|
|
|
|
'2014-03-25 03:59:56.654563',
|
|
|
|
'-U',
|
|
|
|
'2014-03-25 03:59:59.654563',
|
2020-02-22 16:31:31 -07:00
|
|
|
];
|
|
|
|
|
|
|
|
const actualCommand = spawn.firstCall.args[0];
|
2022-12-05 16:24:11 -03:00
|
|
|
const actualOptionalArgs = spawn.firstCall.args[1];
|
2020-02-22 16:31:31 -07:00
|
|
|
|
|
|
|
expect(spawn.calledOnce).to.be.true;
|
|
|
|
|
|
|
|
expect(actualCommand).deep.equal(expectedCommand);
|
|
|
|
|
2020-05-15 12:01:51 +01:00
|
|
|
expectedOptionalArgs.forEach((arg) => {
|
2020-02-22 16:31:31 -07:00
|
|
|
expect(actualOptionalArgs).to.include(arg);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|