Skip to content
Browse files

Code style changes. Bigfixes.

  • Loading branch information...
1 parent ae706b7 commit 2473da1cf8525619fb8396be2a313540510dfe0c @dachev committed May 19, 2013
Showing with 446 additions and 442 deletions.
  1. +51 −50 lib/index.js
  2. +1 −1 package.json
  3. +394 −391 test/runner.js
View
101 lib/index.js
@@ -52,12 +52,12 @@ var Spawn = require('child_process').spawn;
* @param {Function} __callback__
*/
function CronTab(u, cb) {
- var self = this,
- user = u || '',
- root = (process.getuid() == 0),
- backup = {lines:[], jobs:[]},
- lines = [],
- jobs = [];
+ var self = this;
+ var user = u || '';
+ var root = (process.getuid() == 0);
+ var backup = {lines:[], jobs:[]};
+ var lines = [];
+ var jobs = [];
load(cb);
@@ -102,7 +102,8 @@ function CronTab(u, cb) {
this.save = function(cb) {
var stdout = '';
var stderr = '';
- var child = Spawn(COMMAND, ['-']);
+ var args = makeChildArgs('save');
+ var child = Spawn(COMMAND, args);
child.stdout.setEncoding('utf8');
child.stderr.setEncoding('utf8');
@@ -175,10 +176,10 @@ function CronTab(u, cb) {
* @return {CronJob|null}
*/
this.create = function(command) {
- var args = Array.prototype.slice.call(arguments),
- types = args.map(function(arg) { return typeof arg; }),
- comment = (types[1] == 'string') ? args[1] : null,
- job = makeJob(null, command, comment);
+ var args = Array.prototype.slice.call(arguments);
+ var types = args.map(function(arg) { return typeof arg; });
+ var comment = (types[1] == 'string') ? args[1] : null;
+ var job = makeJob(null, command, comment);
if (job == null) { return job; }
@@ -280,8 +281,7 @@ function CronTab(u, cb) {
}
for (var i = 0; i < jobs.length; i++) {
- var job = jobs[i];
- remove(job);
+ remove(jobs[i]);
}
truncateLines();
@@ -314,7 +314,8 @@ function CronTab(u, cb) {
function load(cb) {
var stdout = '';
var stderr = '';
- var child = Spawn(COMMAND, ['-l']);
+ var args = makeChildArgs('load');
+ var child = Spawn(COMMAND, args);
jobs = [];
lines = [];
@@ -437,8 +438,8 @@ function CronTab(u, cb) {
* @api private
*/
function truncateLines() {
- var undefined,
- line = lines.pop();
+ var undefined;
+ var line = lines.pop();
while (line != undefined && line.toString().trim() == '') {
line = lines.pop();
@@ -465,12 +466,12 @@ function CronTab(u, cb) {
* @param {String} __[comment]__
*/
function CronJob(line, c, m) {
- var self = this,
- command = null,
- comment = null,
- valid = false,
- slots = [],
- special = false;
+ var self = this;
+ var command = null;
+ var comment = null;
+ var valid = false;
+ var slots = [];
+ var special = false;
/**
@@ -522,9 +523,9 @@ function CronJob(line, c, m) {
time = tokens.join(' ');
}
- var keys = getKeys.call(SPECIALS),
- vals = getVals.call(SPECIALS),
- timeIdx = vals.indexOf(time);
+ var keys = getKeys.call(SPECIALS);
+ var vals = getVals.call(SPECIALS);
+ var timeIdx = vals.indexOf(time);
if (timeIdx >=0 ) {
time = '@' + keys[timeIdx];
@@ -744,13 +745,13 @@ function CronJob(line, c, m) {
slots = [];
for (var i = 0; i < 5; i++) {
- var info = SINFO[i],
- value = (tokens && tokens[i] || null),
- name = info.name,
- min = info.min,
- max = info.max,
- enumm = info.enumm,
- slot = new TimeSlot(name, min, max, enumm, value);
+ var info = SINFO[i];
+ var value = (tokens && tokens[i] || null);
+ var name = info.name;
+ var min = info.min;
+ var max = info.max;
+ var enumm = info.enumm;
+ var slot = new TimeSlot(name, min, max, enumm, value);
slots.push(slot);
}
@@ -823,12 +824,12 @@ function CronJob(line, c, m) {
* @param {String|null} __value__ a value to parse (e.g '19-0/2,0-3')
*/
function TimeSlot(name, min, max, enumm, value) {
- var self = this,
- name = name,
- min = min,
- max = max,
- enumm = enumm,
- parts = [];
+ var self = this;
+ var name = name;
+ var min = min;
+ var max = max;
+ var enumm = enumm;
+ var parts = [];
/**
@@ -1037,8 +1038,8 @@ function TimeSlot(name, min, max, enumm, value) {
parts.push(range);
}
else {
- var lPart = token.toLowerCase(),
- enummIdx = (enumm || []).indexOf(lPart);
+ var lPart = token.toLowerCase();
+ var enummIdx = (enumm || []).indexOf(lPart);
if (enummIdx >= 0) {
token = enummIdx;
@@ -1076,11 +1077,11 @@ function TimeSlot(name, min, max, enumm, value) {
* @param {String} __range__ The range string e.g. _* / 2_, _jun - sep_
*/
function TimeRange(s, range) {
- var self = this,
- slot = s,
- from = null,
- to = null,
- step = 1;
+ var self = this;
+ var slot = s;
+ var from = null;
+ var to = null;
+ var step = 1;
/**
@@ -1156,9 +1157,9 @@ function TimeRange(s, range) {
* @api private
*/
function cleanValue(value) {
- var sValue = String(value),
- lValue = sValue.toLowerCase(),
- enummIdx = (slot.getEnum() || []).indexOf(lValue);
+ var sValue = String(value);
+ var lValue = sValue.toLowerCase();
+ var enummIdx = (slot.getEnum() || []).indexOf(lValue);
if (enummIdx >= 0) {
value = enummIdx;
@@ -1343,8 +1344,8 @@ function getKeys() {
}
function getVals() {
- var keys = getKeys.call(this),
- vals = [];
+ var keys = getKeys.call(this);
+ var vals = [];
for (var i = 0; i < keys.length; i++) {
var key = keys[i];
View
2 package.json
@@ -11,7 +11,7 @@
"scripts": {
"test": "test/runner.js"
},
- "engines": { "node": ">= 0.6.0" },
+ "engines": { "node": ">= 0.10.0" },
"author": {
"name" : "Blagovest Dachev",
"email" : "blago@dachev.com",
View
785 test/runner.js
@@ -4,450 +4,453 @@ require('child_process').spawn = mockChild;
// Mock child_process
function mockChild(command, args) {
- var undefined,
- action = (args.indexOf('-l') >= 0) ? 'load' : 'save',
- user = '',
- uRegEx = /-u\s([^\s]+)/;
+ var undefined;
+ var action = (args.indexOf('-l') >= 0) ? 'load' : 'save';
+ var user = '';
+ var uRegEx = /-u\s([^\s]+)/;
+
+ for (var i = 0; i < args.length; i++) {
+ var arg = args[i];
+ var tokens = arg.match(uRegEx);
- for (var i = 0; i < args.length; i++) {
- var arg = args[i],
- tokens = arg.match(uRegEx);
-
- user = tokens && tokens[1] || '';
-
- if (user) { break; }
- };
-
- function load(child) {
- process.nextTick(function() {
- if (mockChild.user != 'root' && user != '') {
- child.stderr.emit('data', 'crontab: must be privileged to use -u');
- child.emit('exit', '1');
- return;
- }
-
- var tabs = mockChild.tabs[user || mockChild.user];
- if (tabs == undefined && user != '') {
- child.stderr.emit('data', 'crontab: user ' + user + ' unknown');
- child.emit('exit', '1');
- return;
- }
- if (tabs == null) {
- child.stderr.emit('data', 'crontab: no crontab for ...');
- child.emit('exit', '1');
- return;
- }
-
- child.stdout.emit('data', tabs.join('\n'));
- child.emit('exit', '0');
- });
- }
-
- function save(child, newTabs) {
- process.nextTick(function() {
- if (mockChild.user != 'root' && user != '') {
- child.stderr.emit('data', 'crontab: must be privileged to use -u');
- child.emit('exit', '1');
- }
- else {
- mockChild.tabs[user || mockChild.user] = newTabs.split('\n');
- child.emit('exit', '0');
- }
- });
- }
+ user = tokens && tokens[1] || '';
- var child = new process.EventEmitter;
- child.stdout = new process.EventEmitter;
- child.stderr = new process.EventEmitter;
- child.stdin = {
- buffer : '',
- write : function(tabs) { this.buffer = tabs; },
- end : function(tabs) { save(child, this.buffer); }
- }
-
- if (action == 'load') {
- load(child);
- }
-
- return child;
+ if (user) { break; }
+ };
+
+ function load(child) {
+ process.nextTick(function() {
+ if (mockChild.user != 'root' && user != '') {
+ child.stderr.emit('data', 'crontab: must be privileged to use -u');
+ child.emit('close', 1);
+ return;
+ }
+
+ var tabs = mockChild.tabs[user || mockChild.user];
+ if (tabs == undefined && user != '') {
+ child.stderr.emit('data', 'crontab: user ' + user + ' unknown');
+ child.emit('close', 1);
+ return;
+ }
+ if (tabs == null) {
+ child.stderr.emit('data', 'crontab: no crontab for ...');
+ child.emit('close', 1);
+ return;
+ }
+
+ child.stdout.emit('data', tabs.join('\n'));
+ child.emit('close', 0);
+ });
+ }
+
+ function save(child, newTabs) {
+ process.nextTick(function() {
+ if (mockChild.user != 'root' && user != '') {
+ child.stderr.emit('data', 'crontab: must be privileged to use -u');
+ child.emit('close', 1);
+ }
+ else {
+ mockChild.tabs[user || mockChild.user] = newTabs.split('\n');
+ child.emit('close', 0);
+ }
+ });
+ }
+
+ var child = new process.EventEmitter;
+ child.stdout = new process.EventEmitter;
+ child.stderr = new process.EventEmitter;
+ child.stdin = {
+ buffer : '',
+ write : function(tabs) { this.buffer = tabs; },
+ end : function(tabs) { save(child, this.buffer); }
+ }
+
+ child.stdout.setEncoding =function(){};
+ child.stderr.setEncoding =function(){};
+
+ if (action == 'load') {
+ load(child);
+ }
+
+ return child;
}
mockChild.user = 'blago';
mockChild.tabs = {
- alice : ['0 8-17 * * 1-5 /usr/bin/env echo "check email"',
- '* 19-0,0-3 * * 1-5 /usr/bin/env echo "hack node.js"',
- '30 11 * * 6-0 /usr/bin/env echo "wake up"',
- '* * * 5-8 * /usr/bin/env echo "go to Bulgaria"',
- '30 9 24 12 * /usr/bin/env echo "get presents"'],
- bob : ['0 8-17 * * 1-5 /usr/bin/env echo "check email"',
- '* 19-0,0-3 * * 1-5 /usr/bin/env echo "hack node.js"',
- '30 11 * * 6-0 /usr/bin/env echo "wake up"'],
- blago : null,
- root : [],
- special : ['@reboot /usr/bin/env echo "starting service (reboot)" #reboot',
- '@hourly /usr/bin/env echo "starting service (hourly)"',
- '@daily /usr/bin/env echo "starting service (daily)"',
- '@weekly /usr/bin/env echo "starting service (weekly)"',
- '@monthly /usr/bin/env echo "starting service (monthly)"',
- '@yearly /usr/bin/env echo "starting service (yearly)"',
- '@annually /usr/bin/env echo "starting service (annually)"',
- '@midnight /usr/bin/env echo "starting service (midnight)"'],
- comments: ['0 8-17 * * 1-5 /usr/bin/env echo "check email" #every business hour'],
- commands: ['0 8-17 * * 1-5 /usr/bin/env echo "check email" #every business hour'],
+ alice : ['0 8-17 * * 1-5 /usr/bin/env echo "check email"',
+ '* 19-0,0-3 * * 1-5 /usr/bin/env echo "hack node.js"',
+ '30 11 * * 6-0 /usr/bin/env echo "wake up"',
+ '* * * 5-8 * /usr/bin/env echo "go to Bulgaria"',
+ '30 9 24 12 * /usr/bin/env echo "get presents"'],
+ bob : ['0 8-17 * * 1-5 /usr/bin/env echo "check email"',
+ '* 19-0,0-3 * * 1-5 /usr/bin/env echo "hack node.js"',
+ '30 11 * * 6-0 /usr/bin/env echo "wake up"'],
+ blago : null,
+ root : [],
+ special : ['@reboot /usr/bin/env echo "starting service (reboot)" #reboot',
+ '@hourly /usr/bin/env echo "starting service (hourly)"',
+ '@daily /usr/bin/env echo "starting service (daily)"',
+ '@weekly /usr/bin/env echo "starting service (weekly)"',
+ '@monthly /usr/bin/env echo "starting service (monthly)"',
+ '@yearly /usr/bin/env echo "starting service (yearly)"',
+ '@annually /usr/bin/env echo "starting service (annually)"',
+ '@midnight /usr/bin/env echo "starting service (midnight)"'],
+ comments: ['0 8-17 * * 1-5 /usr/bin/env echo "check email" #every business hour'],
+ commands: ['0 8-17 * * 1-5 /usr/bin/env echo "check email" #every business hour'],
};
// Test helpers
function loadTabs(user) {
- var promise = new(process.EventEmitter);
-
- CronTab.load(user, function(err, tab) {
- if (err) { promise.emit('error', err); }
- else { promise.emit('success', tab); }
- });
-
- return promise;
+ var promise = new(process.EventEmitter);
+
+ CronTab.load(user, function(err, tab) {
+ if (err) { promise.emit('error', err); }
+ else { promise.emit('success', tab); }
+ });
+
+ return promise;
}
function saveTabs(tab) {
- var promise = new(process.EventEmitter);
-
- tab.save(function(err, tab) {
- if (err) { promise.emit('error', err); }
- else { promise.emit('success', tab); }
- });
-
- return promise;
+ var promise = new(process.EventEmitter);
+
+ tab.save(function(err, tab) {
+ if (err) { promise.emit('error', err); }
+ else { promise.emit('success', tab); }
+ });
+
+ return promise;
}
function makeTabArrayFromTopicStack() {
- var tab1 = arguments[0],
- tab2 = arguments[2];
-
- return [tab1, tab2];
+ var tab1 = arguments[0];
+ var tab2 = arguments[2];
+
+ return [tab1, tab2];
}
// Test batches
var nonRootLoadsAnoterUserCrons = {
- 'non-root user loads another user\'s crons': {
- topic: function() {
- mockChild.user = 'blago';
- return loadTabs('alice');
- },
- 'should fail loading':function(err, tab) {
- Assert.isObject(err);
- Assert.isString(err.message);
- Assert.matches(err.message, /privileged/);
- }
+ 'non-root user loads another user\'s crons': {
+ topic: function() {
+ mockChild.user = 'blago';
+ return loadTabs('alice');
+ },
+ 'should fail loading':function(err, tab) {
+ Assert.isObject(err);
+ Assert.isString(err.message);
+ Assert.matches(err.message, /privileged/);
}
+ }
};
var rootLoadsAnoterUserCrons = {
- 'root user loads another (existing) user\'s crons': {
- topic: function() {
- mockChild.user = 'root';
- return loadTabs('bob');
- },
- 'should succeed loading':function(err, tab) {
- rootLoadsAnoterUserCrons.tab = tab;
-
- Assert.isNull(err);
- Assert.isObject(tab);
- Assert.isArray(tab.getJobs());
- Assert.equal(tab.getJobs().length, 3);
- }
+ 'root user loads another (existing) user\'s crons': {
+ topic: function() {
+ mockChild.user = 'root';
+ return loadTabs('bob');
+ },
+ 'should succeed loading':function(err, tab) {
+ rootLoadsAnoterUserCrons.tab = tab;
+
+ Assert.isNull(err);
+ Assert.isObject(tab);
+ Assert.isArray(tab.getJobs());
+ Assert.equal(tab.getJobs().length, 3);
}
+ }
};
var rootLoadsAnoterNonExistingUserCrons = {
- 'root user loads another (non-existing) user\'s crons': {
- topic: function() {
- mockChild.user = 'root';
- return loadTabs('tom');
- },
- 'should fail loading':function(err, tab) {
- Assert.isObject(err);
- Assert.isString(err.message);
- Assert.matches(err.message, /unknown/);
- }
+ 'root user loads another (non-existing) user\'s crons': {
+ topic: function() {
+ mockChild.user = 'root';
+ return loadTabs('tom');
+ },
+ 'should fail loading':function(err, tab) {
+ Assert.isObject(err);
+ Assert.isString(err.message);
+ Assert.matches(err.message, /unknown/);
}
+ }
};
var userLoadsHisOwnEmptyCrons = {
- 'user loads his own (empty) crons': {
- topic: function() {
- mockChild.user = 'blago';
- return loadTabs('');
- },
- 'should succeed loading':function(err, tab) {
- userLoadsHisOwnEmptyCrons.tab = tab;
-
- Assert.isNull(err);
- Assert.isObject(tab);
- Assert.isArray(tab.getJobs());
- Assert.equal(tab.getJobs().length, 0);
- }
+ 'user loads his own (empty) crons': {
+ topic: function() {
+ mockChild.user = 'blago';
+ return loadTabs('');
+ },
+ 'should succeed loading':function(err, tab) {
+ userLoadsHisOwnEmptyCrons.tab = tab;
+
+ Assert.isNull(err);
+ Assert.isObject(tab);
+ Assert.isArray(tab.getJobs());
+ Assert.equal(tab.getJobs().length, 0);
}
+ }
};
var userLoadsHerOwnNonEmptyCrons = {
- 'user loads her own (non-empty) crons': {
- topic: function() {
- mockChild.user = 'alice';
- return loadTabs('');
- },
- 'should succeed loading':function(err, tab) {
- userLoadsHerOwnNonEmptyCrons.tab = tab;
-
- Assert.isNull(err);
- Assert.isObject(tab);
- Assert.isArray(tab.getJobs());
- Assert.equal(tab.getJobs().length, 5);
- }
+ 'user loads her own (non-empty) crons': {
+ topic: function() {
+ mockChild.user = 'alice';
+ return loadTabs('');
+ },
+ 'should succeed loading':function(err, tab) {
+ userLoadsHerOwnNonEmptyCrons.tab = tab;
+
+ Assert.isNull(err);
+ Assert.isObject(tab);
+ Assert.isArray(tab.getJobs());
+ Assert.equal(tab.getJobs().length, 5);
}
+ }
};
var userSavesHerOwnNonEmptyCrons = {
- 'user saves her own (non-empty) crons': {
- topic: function() {
- return saveTabs(userLoadsHerOwnNonEmptyCrons.tab);
- },
- 'should succeed saving':function(err, tab) {
- Assert.isNull(err);
- Assert.isObject(tab);
- }
+ 'user saves her own (non-empty) crons': {
+ topic: function() {
+ return saveTabs(userLoadsHerOwnNonEmptyCrons.tab);
+ },
+ 'should succeed saving':function(err, tab) {
+ Assert.isNull(err);
+ Assert.isObject(tab);
}
+ }
};
var userLoadsHerOwnNonEmptyCronsAgain = {
- 'user loads her own (non-empty) crons again': {
- topic: function() {
- mockChild.user = 'alice';
- return loadTabs('');
- },
- 'should succeed loading':function(err, tab) {
- userLoadsHerOwnNonEmptyCronsAgain.tab = tab;
-
- Assert.isNull(err);
- Assert.isObject(tab);
- Assert.isArray(tab.getJobs());
- Assert.equal(tab.getJobs().length, 5);
- },
- 'are the same':function(err, tab) {
- Assert.equal(tab.render().trim(), mockChild.tabs.alice.join('\n').trim());
- }
+ 'user loads her own (non-empty) crons again': {
+ topic: function() {
+ mockChild.user = 'alice';
+ return loadTabs('');
+ },
+ 'should succeed loading':function(err, tab) {
+ userLoadsHerOwnNonEmptyCronsAgain.tab = tab;
+
+ Assert.isNull(err);
+ Assert.isObject(tab);
+ Assert.isArray(tab.getJobs());
+ Assert.equal(tab.getJobs().length, 5);
+ },
+ 'are the same':function(err, tab) {
+ Assert.equal(tab.render().trim(), mockChild.tabs.alice.join('\n').trim());
}
+ }
};
var canParseSpecialSyntax = {
- 'can parse special cron syntax': {
- topic: function() {
- mockChild.user = 'special';
- return loadTabs('');
- },
- 'should succeed loading':function(err, tab) {
- Assert.isNull(err);
- Assert.isObject(tab);
- Assert.isArray(tab.getJobs());
- Assert.equal(tab.getJobs().length, 8);
- },
- '@reboot':function(err, tab) {
- var jobs = tab.findCommand('reboot'),
- job = jobs[0];
-
- Assert.isArray(jobs);
- Assert.equal(jobs.length, 1);
- Assert.isTrue(job.isValid());
- Assert.equal(job.comment(), 'reboot');
- },
- '@hourly':function(tab) {
- var jobs = tab.findCommand('hourly'),
- job = jobs[0];
-
- Assert.isArray(jobs);
- Assert.equal(jobs.length, 1);
- Assert.isTrue(job.isValid());
- Assert.equal(job.minute().toString(), '0');
- Assert.equal(job.hour().toString(), '*');
- Assert.equal(job.dom().toString(), '*');
- Assert.equal(job.month().toString(), '*');
- Assert.equal(job.dow().toString(), '*');
- },
- '@daily':function(tab) {
- var jobs = tab.findCommand('daily'),
- job = jobs[0];
-
- Assert.isArray(jobs);
- Assert.equal(jobs.length, 1);
- Assert.isTrue(job.isValid());
- Assert.equal(job.minute().toString(), '0');
- Assert.equal(job.hour().toString(), '0');
- Assert.equal(job.dom().toString(), '*');
- Assert.equal(job.month().toString(), '*');
- Assert.equal(job.dow().toString(), '*');
- },
- '@weekly':function(tab) {
- var jobs = tab.findCommand('weekly'),
- job = jobs[0];
-
- Assert.isArray(jobs);
- Assert.equal(jobs.length, 1);
- Assert.isTrue(job.isValid());
- Assert.equal(job.minute().toString(), '0');
- Assert.equal(job.hour().toString(), '0');
- Assert.equal(job.dom().toString(), '*');
- Assert.equal(job.month().toString(), '*');
- Assert.equal(job.dow().toString(), '0');
- },
- '@monthly':function(tab) {
- var jobs = tab.findCommand('monthly'),
- job = jobs[0];
-
- Assert.isArray(jobs);
- Assert.equal(jobs.length, 1);
- Assert.isTrue(job.isValid());
- Assert.equal(job.minute().toString(), '0');
- Assert.equal(job.hour().toString(), '0');
- Assert.equal(job.dom().toString(), '1');
- Assert.equal(job.month().toString(), '*');
- Assert.equal(job.dow().toString(), '*');
- },
- '@yearly':function(tab) {
- var jobs = tab.findCommand('yearly'),
- job = jobs[0];
-
- Assert.isArray(jobs);
- Assert.equal(jobs.length, 1);
- Assert.isTrue(job.isValid());
- Assert.equal(job.minute().toString(), '0');
- Assert.equal(job.hour().toString(), '0');
- Assert.equal(job.dom().toString(), '1');
- Assert.equal(job.month().toString(), '1');
- Assert.equal(job.dow().toString(), '*');
- },
- '@annually':function(tab) {
- var jobs = tab.findCommand('yearly'),
- job = jobs[0];
-
- Assert.isArray(jobs);
- Assert.equal(jobs.length, 1);
- Assert.isTrue(job.isValid());
- Assert.equal(job.minute().toString(), '0');
- Assert.equal(job.hour().toString(), '0');
- Assert.equal(job.dom().toString(), '1');
- Assert.equal(job.month().toString(), '1');
- Assert.equal(job.dow().toString(), '*');
- },
- '@midnight':function(tab) {
- var jobs = tab.findCommand('midnight'),
- job = jobs[0];
-
- Assert.isArray(jobs);
- Assert.equal(jobs.length, 1);
- Assert.isTrue(job.isValid());
- Assert.equal(job.minute().toString(), '0');
- Assert.equal(job.hour().toString(), '0');
- Assert.equal(job.dom().toString(), '*');
- Assert.equal(job.month().toString(), '*');
- Assert.equal(job.dow().toString(), '*');
- }
+ 'can parse special cron syntax': {
+ topic: function() {
+ mockChild.user = 'special';
+ return loadTabs('');
+ },
+ 'should succeed loading':function(err, tab) {
+ Assert.isNull(err);
+ Assert.isObject(tab);
+ Assert.isArray(tab.getJobs());
+ Assert.equal(tab.getJobs().length, 8);
+ },
+ '@reboot':function(err, tab) {
+ var jobs = tab.findCommand('reboot');
+ var job = jobs[0];
+
+ Assert.isArray(jobs);
+ Assert.equal(jobs.length, 1);
+ Assert.isTrue(job.isValid());
+ Assert.equal(job.comment(), 'reboot');
+ },
+ '@hourly':function(tab) {
+ var jobs = tab.findCommand('hourly');
+ var job = jobs[0];
+
+ Assert.isArray(jobs);
+ Assert.equal(jobs.length, 1);
+ Assert.isTrue(job.isValid());
+ Assert.equal(job.minute().toString(), '0');
+ Assert.equal(job.hour().toString(), '*');
+ Assert.equal(job.dom().toString(), '*');
+ Assert.equal(job.month().toString(), '*');
+ Assert.equal(job.dow().toString(), '*');
+ },
+ '@daily':function(tab) {
+ var jobs = tab.findCommand('daily');
+ var job = jobs[0];
+
+ Assert.isArray(jobs);
+ Assert.equal(jobs.length, 1);
+ Assert.isTrue(job.isValid());
+ Assert.equal(job.minute().toString(), '0');
+ Assert.equal(job.hour().toString(), '0');
+ Assert.equal(job.dom().toString(), '*');
+ Assert.equal(job.month().toString(), '*');
+ Assert.equal(job.dow().toString(), '*');
+ },
+ '@weekly':function(tab) {
+ var jobs = tab.findCommand('weekly');
+ var job = jobs[0];
+
+ Assert.isArray(jobs);
+ Assert.equal(jobs.length, 1);
+ Assert.isTrue(job.isValid());
+ Assert.equal(job.minute().toString(), '0');
+ Assert.equal(job.hour().toString(), '0');
+ Assert.equal(job.dom().toString(), '*');
+ Assert.equal(job.month().toString(), '*');
+ Assert.equal(job.dow().toString(), '0');
+ },
+ '@monthly':function(tab) {
+ var jobs = tab.findCommand('monthly');
+ var job = jobs[0];
+
+ Assert.isArray(jobs);
+ Assert.equal(jobs.length, 1);
+ Assert.isTrue(job.isValid());
+ Assert.equal(job.minute().toString(), '0');
+ Assert.equal(job.hour().toString(), '0');
+ Assert.equal(job.dom().toString(), '1');
+ Assert.equal(job.month().toString(), '*');
+ Assert.equal(job.dow().toString(), '*');
+ },
+ '@yearly':function(tab) {
+ var jobs = tab.findCommand('yearly');
+ var job = jobs[0];
+
+ Assert.isArray(jobs);
+ Assert.equal(jobs.length, 1);
+ Assert.isTrue(job.isValid());
+ Assert.equal(job.minute().toString(), '0');
+ Assert.equal(job.hour().toString(), '0');
+ Assert.equal(job.dom().toString(), '1');
+ Assert.equal(job.month().toString(), '1');
+ Assert.equal(job.dow().toString(), '*');
+ },
+ '@annually':function(tab) {
+ var jobs = tab.findCommand('yearly');
+ var job = jobs[0];
+
+ Assert.isArray(jobs);
+ Assert.equal(jobs.length, 1);
+ Assert.isTrue(job.isValid());
+ Assert.equal(job.minute().toString(), '0');
+ Assert.equal(job.hour().toString(), '0');
+ Assert.equal(job.dom().toString(), '1');
+ Assert.equal(job.month().toString(), '1');
+ Assert.equal(job.dow().toString(), '*');
+ },
+ '@midnight':function(tab) {
+ var jobs = tab.findCommand('midnight');
+ var job = jobs[0];
+
+ Assert.isArray(jobs);
+ Assert.equal(jobs.length, 1);
+ Assert.isTrue(job.isValid());
+ Assert.equal(job.minute().toString(), '0');
+ Assert.equal(job.hour().toString(), '0');
+ Assert.equal(job.dom().toString(), '*');
+ Assert.equal(job.month().toString(), '*');
+ Assert.equal(job.dow().toString(), '*');
}
+ }
};
var canParseCommands = {
- 'can parse commands' : {
- topic: function() {
- mockChild.user = 'commands';
- return loadTabs('');
- },
- 'should succeed loading':function(err, tab) {
- Assert.isNull(err);
- Assert.isObject(tab);
- Assert.isArray(tab.getJobs());
- Assert.equal(tab.getJobs().length, 1);
- },
- 'command should match':function(err, tab) {
- var job = tab.getJobs()[0];
- Assert.equal(job.command(), '/usr/bin/env echo "check email"');
- }
+ 'can parse commands' : {
+ topic: function() {
+ mockChild.user = 'commands';
+ return loadTabs('');
+ },
+ 'should succeed loading':function(err, tab) {
+ Assert.isNull(err);
+ Assert.isObject(tab);
+ Assert.isArray(tab.getJobs());
+ Assert.equal(tab.getJobs().length, 1);
+ },
+ 'command should match':function(err, tab) {
+ var job = tab.getJobs()[0];
+ Assert.equal(job.command(), '/usr/bin/env echo "check email"');
}
+ }
}
var canParseInlineComments = {
- 'can parse inline comments' : {
- topic: function() {
- mockChild.user = 'comments';
- return loadTabs('');
- },
- 'should succeed loading':function(err, tab) {
- Assert.isNull(err);
- Assert.isObject(tab);
- Assert.isArray(tab.getJobs());
- Assert.equal(tab.getJobs().length, 1);
- },
- 'comment should match':function(err, tab) {
- var job = tab.getJobs()[0];
- Assert.equal(job.comment(), 'every business hour');
- }
+ 'can parse inline comments' : {
+ topic: function() {
+ mockChild.user = 'comments';
+ return loadTabs('');
+ },
+ 'should succeed loading':function(err, tab) {
+ Assert.isNull(err);
+ Assert.isObject(tab);
+ Assert.isArray(tab.getJobs());
+ Assert.equal(tab.getJobs().length, 1);
+ },
+ 'comment should match':function(err, tab) {
+ var job = tab.getJobs()[0];
+ Assert.equal(job.comment(), 'every business hour');
}
+ }
};
var canFindJobsByCommand = {
- 'can find jobs by command' : {
- topic: function() {
- mockChild.user = 'commands';
- return loadTabs('');
- },
- 'should succeed loading':function(err, tab) {
- Assert.isNull(err);
- Assert.isObject(tab);
- Assert.isArray(tab.getJobs());
- Assert.equal(tab.getJobs().length, 1);
- },
- 'should find jobs by substring':function(err, tab) {
- var jobs = tab.findCommand('/usr/bin/env echo');
-
- Assert.isArray(jobs);
- Assert.equal(jobs.length, 1);
- },
- 'should find jobs by regular expression':function(err, tab) {
- var jobs = tab.findCommand(/echo/);
-
- Assert.isArray(jobs);
- Assert.equal(jobs.length, 1);
- }
- }
+ 'can find jobs by command' : {
+ topic: function() {
+ mockChild.user = 'commands';
+ return loadTabs('');
+ },
+ 'should succeed loading':function(err, tab) {
+ Assert.isNull(err);
+ Assert.isObject(tab);
+ Assert.isArray(tab.getJobs());
+ Assert.equal(tab.getJobs().length, 1);
+ },
+ 'should find jobs by substring':function(err, tab) {
+ var jobs = tab.findCommand('/usr/bin/env echo');
+
+ Assert.isArray(jobs);
+ Assert.equal(jobs.length, 1);
+ },
+ 'should find jobs by regular expression':function(err, tab) {
+ var jobs = tab.findCommand(/echo/);
+
+ Assert.isArray(jobs);
+ Assert.equal(jobs.length, 1);
+ }
+ }
};
var canFindJobsByComment = {
- 'can find jobs by comment' : {
- topic: function() {
- mockChild.user = 'comments';
- return loadTabs('');
- },
- 'should succeed loading':function(err, tab) {
- Assert.isNull(err);
- Assert.isObject(tab);
- Assert.isArray(tab.getJobs());
- Assert.equal(tab.getJobs().length, 1);
- },
- 'should find jobs by substring':function(err, tab) {
- var jobs = tab.findComment('every business hour');
-
- Assert.isArray(jobs);
- Assert.equal(jobs.length, 1);
- },
- 'should find jobs by regular expression':function(err, tab) {
- var jobs = tab.findComment(/business/);
-
- Assert.isArray(jobs);
- Assert.equal(jobs.length, 1);
- }
+ 'can find jobs by comment' : {
+ topic: function() {
+ mockChild.user = 'comments';
+ return loadTabs('');
+ },
+ 'should succeed loading':function(err, tab) {
+ Assert.isNull(err);
+ Assert.isObject(tab);
+ Assert.isArray(tab.getJobs());
+ Assert.equal(tab.getJobs().length, 1);
+ },
+ 'should find jobs by substring':function(err, tab) {
+ var jobs = tab.findComment('every business hour');
+
+ Assert.isArray(jobs);
+ Assert.equal(jobs.length, 1);
+ },
+ 'should find jobs by regular expression':function(err, tab) {
+ var jobs = tab.findComment(/business/);
+
+ Assert.isArray(jobs);
+ Assert.equal(jobs.length, 1);
}
+ }
};
-var Vows = require('vows'),
- Assert = require('assert'),
- CronTab = require('../lib/index');
+var Vows = require('vows');
+var Assert = require('assert');
+var CronTab = require('../lib/index');
Vows.describe('crontab').
- addBatch(nonRootLoadsAnoterUserCrons).
- addBatch(rootLoadsAnoterUserCrons).
- addBatch(rootLoadsAnoterNonExistingUserCrons).
- addBatch(userLoadsHisOwnEmptyCrons).
- addBatch(userLoadsHerOwnNonEmptyCrons).
- addBatch(userSavesHerOwnNonEmptyCrons).
- addBatch(userLoadsHerOwnNonEmptyCronsAgain).
- addBatch(canParseSpecialSyntax).
- addBatch(canParseCommands).
- addBatch(canParseInlineComments).
- addBatch(canFindJobsByCommand).
- addBatch(canFindJobsByComment).
- export(module);
+ addBatch(nonRootLoadsAnoterUserCrons).
+ addBatch(rootLoadsAnoterUserCrons).
+ addBatch(rootLoadsAnoterNonExistingUserCrons).
+ addBatch(userLoadsHisOwnEmptyCrons).
+ addBatch(userLoadsHerOwnNonEmptyCrons).
+ addBatch(userSavesHerOwnNonEmptyCrons).
+ addBatch(userLoadsHerOwnNonEmptyCronsAgain).
+ addBatch(canParseSpecialSyntax).
+ addBatch(canParseCommands).
+ addBatch(canParseInlineComments).
+ addBatch(canFindJobsByCommand).
+ addBatch(canFindJobsByComment).
+ export(module);

0 comments on commit 2473da1

Please sign in to comment.
Something went wrong with that request. Please try again.