|
|
|
@ -20,10 +20,13 @@ module.exports.tests.completely_valid = (test, common) => {
|
|
|
|
|
requestRetries: 19, |
|
|
|
|
services: { |
|
|
|
|
pip: { |
|
|
|
|
url: 'http://locahost' |
|
|
|
|
url: 'http://localhost' |
|
|
|
|
}, |
|
|
|
|
placeholder: { |
|
|
|
|
url: 'http://locahost' |
|
|
|
|
url: 'http://localhost' |
|
|
|
|
}, |
|
|
|
|
language: { |
|
|
|
|
url: 'http://localhost' |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
defaultParameters: { |
|
|
|
@ -941,6 +944,284 @@ module.exports.tests.pip_service_validation = (test, common) => {
|
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
module.exports.tests.language_service_validation = (test, common) => { |
|
|
|
|
test('timeout and retries not specified should default to 250 and 3', (t) => { |
|
|
|
|
const config = { |
|
|
|
|
api: { |
|
|
|
|
version: 'version value', |
|
|
|
|
indexName: 'index name value', |
|
|
|
|
host: 'host value', |
|
|
|
|
services: { |
|
|
|
|
language: { |
|
|
|
|
url: 'http://localhost' |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
esclient: {} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const result = Joi.validate(config, schema); |
|
|
|
|
|
|
|
|
|
t.equals(result.value.api.services.language.timeout, 250); |
|
|
|
|
t.equals(result.value.api.services.language.retries, 3); |
|
|
|
|
t.end(); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
test('when api.services.language is defined, url is required', (t) => { |
|
|
|
|
var config = { |
|
|
|
|
api: { |
|
|
|
|
version: 'version value', |
|
|
|
|
indexName: 'index name value', |
|
|
|
|
host: 'host value', |
|
|
|
|
services: { |
|
|
|
|
language: { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
esclient: {} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const result = Joi.validate(config, schema); |
|
|
|
|
|
|
|
|
|
t.equals(result.error.details.length, 1); |
|
|
|
|
t.equals(result.error.details[0].message, '"url" is required'); |
|
|
|
|
t.end(); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
test('non-string api.services.language.url should throw error', (t) => { |
|
|
|
|
[null, 17, {}, [], true].forEach((value) => { |
|
|
|
|
var config = { |
|
|
|
|
api: { |
|
|
|
|
version: 'version value', |
|
|
|
|
indexName: 'index name value', |
|
|
|
|
host: 'host value', |
|
|
|
|
services: { |
|
|
|
|
language: { |
|
|
|
|
url: value |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
esclient: {} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const result = Joi.validate(config, schema); |
|
|
|
|
|
|
|
|
|
t.equals(result.error.details.length, 1); |
|
|
|
|
t.equals(result.error.details[0].message, '"url" must be a string'); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
t.end(); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
test('non-http/https api.services.language.url should throw error', (t) => { |
|
|
|
|
['ftp', 'git', 'unknown'].forEach((scheme) => { |
|
|
|
|
var config = { |
|
|
|
|
api: { |
|
|
|
|
version: 'version value', |
|
|
|
|
indexName: 'index name value', |
|
|
|
|
host: 'host value', |
|
|
|
|
services: { |
|
|
|
|
language: { |
|
|
|
|
url: `${scheme}://localhost` |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
esclient: {} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const result = Joi.validate(config, schema); |
|
|
|
|
|
|
|
|
|
t.equals(result.error.details.length, 1); |
|
|
|
|
t.equals(result.error.details[0].message, '"url" must be a valid uri with a scheme matching the https\? pattern'); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
t.end(); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
test('non-url children of api.services.language should be disallowed', (t) => { |
|
|
|
|
var config = { |
|
|
|
|
api: { |
|
|
|
|
version: 'version value', |
|
|
|
|
indexName: 'index name value', |
|
|
|
|
host: 'host value', |
|
|
|
|
services: { |
|
|
|
|
language: { |
|
|
|
|
url: 'http://localhost', |
|
|
|
|
unknown_property: 'value' |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
esclient: {} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const result = Joi.validate(config, schema); |
|
|
|
|
|
|
|
|
|
t.equals(result.error.details.length, 1); |
|
|
|
|
t.equals(result.error.details[0].message, '"unknown_property" is not allowed'); |
|
|
|
|
t.end(); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
test('non-number timeout should throw error', (t) => { |
|
|
|
|
[null, 'string', {}, [], false].forEach((value) => { |
|
|
|
|
const config = { |
|
|
|
|
api: { |
|
|
|
|
version: 'version value', |
|
|
|
|
indexName: 'index name value', |
|
|
|
|
host: 'host value', |
|
|
|
|
services: { |
|
|
|
|
language: { |
|
|
|
|
url: 'http://localhost', |
|
|
|
|
timeout: value |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
esclient: {} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const result = Joi.validate(config, schema); |
|
|
|
|
|
|
|
|
|
t.equals(result.error.details.length, 1); |
|
|
|
|
t.equals(result.error.details[0].message, '"timeout" must be a number'); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
t.end(); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
test('non-integer timeout should throw error', (t) => { |
|
|
|
|
const config = { |
|
|
|
|
api: { |
|
|
|
|
version: 'version value', |
|
|
|
|
indexName: 'index name value', |
|
|
|
|
host: 'host value', |
|
|
|
|
services: { |
|
|
|
|
language: { |
|
|
|
|
url: 'http://localhost', |
|
|
|
|
timeout: 17.3 |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
esclient: {} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const result = Joi.validate(config, schema); |
|
|
|
|
|
|
|
|
|
t.equals(result.error.details.length, 1); |
|
|
|
|
t.equals(result.error.details[0].message, '"timeout" must be an integer'); |
|
|
|
|
t.end(); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
test('negative timeout should throw error', (t) => { |
|
|
|
|
const config = { |
|
|
|
|
api: { |
|
|
|
|
version: 'version value', |
|
|
|
|
indexName: 'index name value', |
|
|
|
|
host: 'host value', |
|
|
|
|
services: { |
|
|
|
|
language: { |
|
|
|
|
url: 'http://localhost', |
|
|
|
|
timeout: -1 |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
esclient: {} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const result = Joi.validate(config, schema); |
|
|
|
|
|
|
|
|
|
t.equals(result.error.details.length, 1); |
|
|
|
|
t.equals(result.error.details[0].message, '"timeout" must be larger than or equal to 0'); |
|
|
|
|
t.end(); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
test('non-number retries should throw error', (t) => { |
|
|
|
|
[null, 'string', {}, [], false].forEach((value) => { |
|
|
|
|
const config = { |
|
|
|
|
api: { |
|
|
|
|
version: 'version value', |
|
|
|
|
indexName: 'index name value', |
|
|
|
|
host: 'host value', |
|
|
|
|
services: { |
|
|
|
|
language: { |
|
|
|
|
url: 'http://localhost', |
|
|
|
|
retries: value |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
esclient: {} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const result = Joi.validate(config, schema); |
|
|
|
|
|
|
|
|
|
t.equals(result.error.details.length, 1); |
|
|
|
|
t.equals(result.error.details[0].message, '"retries" must be a number'); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
t.end(); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
test('non-integer retries should throw error', (t) => { |
|
|
|
|
const config = { |
|
|
|
|
api: { |
|
|
|
|
version: 'version value', |
|
|
|
|
indexName: 'index name value', |
|
|
|
|
host: 'host value', |
|
|
|
|
services: { |
|
|
|
|
language: { |
|
|
|
|
url: 'http://localhost', |
|
|
|
|
retries: 17.3 |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
esclient: {} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const result = Joi.validate(config, schema); |
|
|
|
|
|
|
|
|
|
t.equals(result.error.details.length, 1); |
|
|
|
|
t.equals(result.error.details[0].message, '"retries" must be an integer'); |
|
|
|
|
t.end(); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
test('negative retries should throw error', (t) => { |
|
|
|
|
const config = { |
|
|
|
|
api: { |
|
|
|
|
version: 'version value', |
|
|
|
|
indexName: 'index name value', |
|
|
|
|
host: 'host value', |
|
|
|
|
services: { |
|
|
|
|
language: { |
|
|
|
|
url: 'http://localhost', |
|
|
|
|
retries: -1 |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
esclient: {} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const result = Joi.validate(config, schema); |
|
|
|
|
|
|
|
|
|
t.equals(result.error.details.length, 1); |
|
|
|
|
t.equals(result.error.details[0].message, '"retries" must be larger than or equal to 0'); |
|
|
|
|
t.end(); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
module.exports.tests.esclient_validation = (test, common) => { |
|
|
|
|
test('config without esclient should throw error', (t) => { |
|
|
|
|
var config = { |
|
|
|
|