add crontab tests

This commit is contained in:
Girish Ramakrishnan
2021-09-28 11:08:10 -07:00
parent 74ce00d94d
commit 13644624df
2 changed files with 38 additions and 2 deletions

View File

@@ -317,4 +317,40 @@ describe('Apps', function () {
expect(result[2].installationState).to.be(apps.ISTATE_PENDING_INSTALL);
});
});
describe('parseCrontab', function () {
it('succeeds for null crontob', function () {
expect(apps._parseCrontab(null)).to.eql([]);
});
it('succeeds for empty crontob', function () {
expect(apps._parseCrontab('')).to.eql([]);
});
it('throws for bad crontab', function () {
safe(() => apps._parseCrontab('# some comment\n*/1 * * * ')); // incomplete pattern
expect(safe.error.message).to.be('Invalid cron configuration at line 2');
safe(() => apps._parseCrontab('* * * * 13 command')); // bad pattern
expect(safe.error.message).to.be('Invalid cron pattern at line 1');
safe(() => apps._parseCrontab('*/1 * * *\t* ')); // no command
expect(safe.error.message).to.be('Invalid cron configuration at line 1');
});
it('succeeds for crontab', function () {
const result = apps._parseCrontab(
'# this is a custom cron job\n' +
' */1 * * *\t* echo "==> This is a custom cron task running every minute"\n\n' +
'00 */1 * * * echo "==> This is a custom cron task running every hour" '); // trailing spaces are trimmed
expect(result.length).to.be(2);
expect(result[0].schedule).to.be('*/1 * * * *');
expect(result[0].command).to.be('echo "==> This is a custom cron task running every minute"');
expect(result[1].schedule).to.be('00 */1 * * *');
expect(result[1].command).to.be('echo "==> This is a custom cron task running every hour"');
});
});
});