diff --git a/src/configValidation.js b/src/configValidation.js index 621f883b..cd738427 100644 --- a/src/configValidation.js +++ b/src/configValidation.js @@ -22,6 +22,7 @@ const schema = Joi.object().keys({ legacyUrl: Joi.string(), accessLog: Joi.string(), relativeScores: Joi.boolean(), + requestRetries: Joi.number().integer().min(0), localization: Joi.object().keys({ flipNumberAndStreetCountries: Joi.array().items(Joi.string().regex(/^[A-Z]{3}$/)) }).unknown(false) diff --git a/test/unit/src/configValidation.js b/test/unit/src/configValidation.js index 91b34312..e492fd19 100644 --- a/test/unit/src/configValidation.js +++ b/test/unit/src/configValidation.js @@ -16,7 +16,8 @@ module.exports.tests.completely_valid = function(test, common) { relativeScores: true, localization: { flipNumberAndStreetCountries: ['ABC', 'DEF'] - } + }, + requestRetries: 19 }, esclient: { requestTimeout: 17 @@ -318,6 +319,65 @@ module.exports.tests.api_validation = function(test, common) { }); + test('config with non-number api.requestRetries should throw error', function(t) { + [null, 'string', {}, [], false].forEach((value) => { + var config = { + api: { + version: 'version value', + indexName: 'index name value', + host: 'host value', + requestRetries: value + }, + esclient: {} + }; + + t.throws(function() { + configValidation.validate(config); + }, /"requestRetries" must be a number/, 'api.requestRetries should be a number'); + }); + + t.end(); + + }); + + test('config with non-integer api.requestRetries should throw error', function(t) { + var config = { + api: { + version: 'version value', + indexName: 'index name value', + host: 'host value', + requestRetries: 17.3 + }, + esclient: {} + }; + + t.throws(function() { + configValidation.validate(config); + }, /"requestRetries" must be an integer/, 'api.requestRetries should be an integer'); + + t.end(); + + }); + + test('config with negative api.requestRetries should throw error', function(t) { + var config = { + api: { + version: 'version value', + indexName: 'index name value', + host: 'host value', + requestRetries: -1 + }, + esclient: {} + }; + + t.throws(function() { + configValidation.validate(config); + }, /"requestRetries" must be larger than or equal to 0/, 'api.requestRetries must be positive'); + + t.end(); + + }); + }; module.exports.tests.esclient_validation = function(test, common) { @@ -358,7 +418,7 @@ module.exports.tests.esclient_validation = function(test, common) { }); - test('config with non-integer esclient.requestTimeout should throw error', function(t) { + test('config with non-number esclient.requestTimeout should throw error', function(t) { [null, 'string', {}, [], false].forEach((value) => { var config = { api: {