Example #1
0
function isValidCheck(value, options, callback) {
  var checkName, checkModule, checkClass, index;

  if (typeof(value) !== 'object') {
    callback(new Error('Health check item, must be an object'));
    return;
  }

  if (!value.hasOwnProperty('check')) {
      callback(new Error('Missing "check" property'));
      return;
  }

  checkName = value.check;

  // Check for a valid check name
  index = misc.arrayFind(checkName,
                          health.availableChecks,
                          null,
                          function(item, needle) {
                            return item[0] === needle;
                          });

  if (index === false) {
    callback(new Error(sprintf('Invalid check type: %s', checkName)));
    return;
  }

  checkModule = require(sprintf('health/checks/%s', checkName));
  checkClass = health.availableChecks[index][1];

  // Create a check object which throws an exception if a required argument is missing
  try {
    var module = new checkModule[checkClass](value['arguments']);
  }
  catch (error) {
    callback(error);
    return;
  }

  callback();
}
Example #2
0
exports['test_arrayFind'] = function() {
  var haystack = [ 'item 1', 'item 2', 'item 3', 'item 4' ];

  assert.equal(misc.arrayFind('item 2', haystack), 1);
  assert.equal(misc.arrayFind('not in array', haystack), false);
};