clear the snapshot repos after every doc

This commit is contained in:
Spencer Alger
2015-07-02 13:04:27 -07:00
parent c1f584cd3e
commit 863cb7a61c
4 changed files with 36 additions and 18 deletions

View File

@ -14,6 +14,7 @@ var path = require('path');
var fs = require('fs');
var async = require('async');
var fromRoot = _.bindKey(path, 'join', require('find-root')(__dirname));
var Promise = require('bluebird');
// current client
var client = null;
@ -98,15 +99,36 @@ module.exports = {
log: logConfig
});
client.clearEs = function (done) {
async.parallel([
function (done) {
client.indices.delete({ index: '*', ignore: 404 }, done);
},
function (done) {
client.indices.deleteTemplate({ name: '*', ignore: 404 }, done);
}
], done);
client.clearEs = function () {
return Promise.all([
client.indices.delete({ index: '*', ignore: 404 }),
client.indices.deleteTemplate({ name: '*', ignore: 404 }),
client.snapshot.getRepository({
snapshot: '_all'
})
.then(_.keys)
.map(function (repo) {
return client.snapshot.get({
repository: repo,
snapshot: '_all'
})
.catch(_.noop)
.then(function (resp) {
return _.pluck(resp.snapshots, 'snapshot');
})
.map(function (snapshot) {
return client.snapshot.delete({
repository: repo,
snapshot: snapshot
});
})
.then(function () {
return client.snapshot.deleteRepository({
repository: repo
});
});
})
]);
};
_.nextTick(cb);

View File

@ -26,9 +26,10 @@ module.exports = function (branch) {
clientManager.create(apiVersion, port, done);
});
before(function (done) {
before(function () {
// make sure ES is empty
clientManager.get().clearEs(done);
this.timeout(0);
return clientManager.get().clearEs();
});
var files = _.map(require('./yaml_tests_' + _.snakeCase(branch) + '.json'), function (docs, filename) {

View File

@ -103,11 +103,6 @@ function rangeMatchesCurrentVersion(rangeString, done) {
}
// empty all of the indices in ES please
function clearIndices(done) {
clientManager.get().clearEs(done);
}
function YamlDoc(doc, file) {
var self = this;

View File

@ -29,8 +29,8 @@ function YamlFile(filename, docs) {
}
});
afterEach(/* doc */function (done) {
clientManager.get().clearEs(done);
afterEach(/* doc */function () {
return clientManager.get().clearEs();
});
});