Browse Source

added pip config + tests to schema

pull/875/head
Stephen Hess 8 years ago
parent
commit
914e508e41
  1. 3
      schema.js
  2. 98
      test/unit/schema.js

3
schema.js

@ -29,6 +29,9 @@ module.exports = Joi.object().keys({
pipService: Joi.string().uri({ scheme: /https?/ }), pipService: Joi.string().uri({ scheme: /https?/ }),
placeholderService: Joi.any().forbidden(), // got moved to services placeholderService: Joi.any().forbidden(), // got moved to services
services: Joi.object().keys({ services: Joi.object().keys({
pip: Joi.object().keys({
url: Joi.string().uri({ scheme: /https?/ })
}).unknown(false).requiredKeys('url'),
placeholder: Joi.object().keys({ placeholder: Joi.object().keys({
url: Joi.string().uri({ scheme: /https?/ }) url: Joi.string().uri({ scheme: /https?/ })
}).unknown(false).requiredKeys('url') }).unknown(false).requiredKeys('url')

98
test/unit/schema.js

@ -523,6 +523,85 @@ module.exports.tests.api_services_validation = (test, common) => {
}); });
};
module.exports.tests.placeholder_service_validation = (test, common) => {
test('when api.services.placeholder is defined, url is required', (t) => {
var config = {
api: {
version: 'version value',
indexName: 'index name value',
host: 'host value',
services: {
placeholder: {
}
}
},
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.placeholder.url should throw error', (t) => {
[null, 17, {}, [], true].forEach((value) => {
var config = {
api: {
version: 'version value',
indexName: 'index name value',
host: 'host value',
services: {
placeholder: {
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.placeholder.url should throw error', (t) => {
['ftp', 'git', 'unknown'].forEach((scheme) => {
var config = {
api: {
version: 'version value',
indexName: 'index name value',
host: 'host value',
services: {
placeholder: {
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.placeholder should be disallowed', (t) => { test('non-url children of api.services.placeholder should be disallowed', (t) => {
var config = { var config = {
api: { api: {
@ -547,14 +626,17 @@ module.exports.tests.api_services_validation = (test, common) => {
}); });
test('when api.services.placeholder is defined, url is required', (t) => { };
module.exports.tests.pip_service_validation = (test, common) => {
test('when api.services.pip is defined, url is required', (t) => {
var config = { var config = {
api: { api: {
version: 'version value', version: 'version value',
indexName: 'index name value', indexName: 'index name value',
host: 'host value', host: 'host value',
services: { services: {
placeholder: { pip: {
} }
} }
}, },
@ -569,7 +651,7 @@ module.exports.tests.api_services_validation = (test, common) => {
}); });
test('non-string api.services.placeholder.url should throw error', (t) => { test('non-string api.services.pip.url should throw error', (t) => {
[null, 17, {}, [], true].forEach((value) => { [null, 17, {}, [], true].forEach((value) => {
var config = { var config = {
api: { api: {
@ -577,7 +659,7 @@ module.exports.tests.api_services_validation = (test, common) => {
indexName: 'index name value', indexName: 'index name value',
host: 'host value', host: 'host value',
services: { services: {
placeholder: { pip: {
url: value url: value
} }
} }
@ -596,7 +678,7 @@ module.exports.tests.api_services_validation = (test, common) => {
}); });
test('non-http/https api.services.placeholder.url should throw error', (t) => { test('non-http/https api.services.pip.url should throw error', (t) => {
['ftp', 'git', 'unknown'].forEach((scheme) => { ['ftp', 'git', 'unknown'].forEach((scheme) => {
var config = { var config = {
api: { api: {
@ -604,7 +686,7 @@ module.exports.tests.api_services_validation = (test, common) => {
indexName: 'index name value', indexName: 'index name value',
host: 'host value', host: 'host value',
services: { services: {
placeholder: { pip: {
url: `${scheme}://localhost` url: `${scheme}://localhost`
} }
} }
@ -623,14 +705,14 @@ module.exports.tests.api_services_validation = (test, common) => {
}); });
test('non-url children of api.services.placeholder should be disallowed', (t) => { test('non-url children of api.services.pip should be disallowed', (t) => {
var config = { var config = {
api: { api: {
version: 'version value', version: 'version value',
indexName: 'index name value', indexName: 'index name value',
host: 'host value', host: 'host value',
services: { services: {
placeholder: { pip: {
url: 'http://localhost', url: 'http://localhost',
unknown_property: 'value' unknown_property: 'value'
} }

Loading…
Cancel
Save