Skip to content

Commit

Permalink
feat(dynamic_type_name): support for dynamically specifying the elast…
Browse files Browse the repository at this point in the history
…icsearch _type from config
  • Loading branch information
missinglink committed Nov 25, 2019
1 parent 1003f7f commit b1f779a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 17 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
"tape": "^4.4.0"
},
"dependencies": {
"elasticsearch": "^16.0.0",
"@hapi/joi": "^15.0.0",
"pelias-config": "^4.0.0",
"elasticsearch": "^16.0.0",
"pelias-config": "^4.5.0",
"pelias-logger": "^1.2.1",
"through2": "^3.0.0"
},
Expand Down
8 changes: 6 additions & 2 deletions src/configValidation.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ const schema = Joi.object().keys({
requestTimeout: Joi.number().integer().min(0)
}).unknown(true),
schema: Joi.object().keys({
indexName: Joi.string()
indexName: Joi.string(),
typeName: Joi.string()
})
}).requiredKeys('dbclient', 'dbclient.statFrequency', 'esclient', 'schema.indexName').unknown(true);
}).requiredKeys(
'dbclient', 'dbclient.statFrequency', 'esclient',
'schema.indexName', 'schema.typeName'
).unknown(true);

module.exports = {
validate: function validate(config) {
Expand Down
37 changes: 24 additions & 13 deletions test/configValidation.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ module.exports.tests.validate = function(test, common) {
var config = {
esclient: {},
schema: {
indexName: 'index_name'
indexName: 'example_index',
typeName: 'example_type'
}
};

Expand All @@ -27,7 +28,8 @@ module.exports.tests.validate = function(test, common) {
dbclient: {},
esclient: {},
schema: {
indexName: 'index_name'
indexName: 'example_index',
typeName: 'example_type'
}
};

Expand All @@ -46,7 +48,8 @@ module.exports.tests.validate = function(test, common) {
},
esclient: {},
schema: {
indexName: 'index_name'
indexName: 'example_index',
typeName: 'example_type'
}
};

Expand All @@ -67,7 +70,8 @@ module.exports.tests.validate = function(test, common) {
},
esclient: {},
schema: {
indexName: 'index_name'
indexName: 'example_index',
typeName: 'example_type'
}
};

Expand All @@ -87,7 +91,8 @@ module.exports.tests.validate = function(test, common) {
},
esclient: value,
schema: {
indexName: 'index_name'
indexName: 'example_index',
typeName: 'example_type'
}
};

Expand All @@ -111,7 +116,8 @@ module.exports.tests.validate = function(test, common) {
requestTimeout: value
},
schema: {
indexName: 'index_name'
indexName: 'example_index',
typeName: 'example_type'
}
};

Expand All @@ -133,7 +139,8 @@ module.exports.tests.validate = function(test, common) {
requestTimeout: 17.3
},
schema: {
indexName: 'index_name'
indexName: 'example_index',
typeName: 'example_type'
}
};

Expand All @@ -154,7 +161,8 @@ module.exports.tests.validate = function(test, common) {
requestTimeout: -1
},
schema: {
indexName: 'index_name'
indexName: 'example_index',
typeName: 'example_type'
}
};

Expand Down Expand Up @@ -231,7 +239,8 @@ module.exports.tests.validate = function(test, common) {
},
esclient: {},
schema: {
indexName: 'index_name'
indexName: 'example_index',
typeName: 'example_type'
}
};

Expand All @@ -258,7 +267,8 @@ module.exports.tests.validate = function(test, common) {
requestTimeout: 17
},
schema: {
indexName: 'index_name'
indexName: 'example_index',
typeName: 'example_type'
}
};

Expand Down Expand Up @@ -286,7 +296,8 @@ module.exports.tests.validate = function(test, common) {
requestTimeout: 17
},
schema: {
indexName: 'index_name'
indexName: 'example_index',
typeName: 'example_type'
}
};

Expand All @@ -307,9 +318,9 @@ module.exports.tests.validate = function(test, common) {
}
}).validate(config);

}, /elasticsearch index index_name does not exist/);
}, /elasticsearch index example_index does not exist/);

t.ok(stderr.match(/ERROR: Elasticsearch index index_name does not exist/));
t.ok(stderr.match(/ERROR: Elasticsearch index example_index does not exist/));

unhook_intercept();
t.end();
Expand Down

0 comments on commit b1f779a

Please sign in to comment.