Skip to content

Commit

Permalink
Merge pull request #784 from stephenplusplus/spp--search-tests
Browse files Browse the repository at this point in the history
system tests: search: delete documents individually
  • Loading branch information
callmehiphop committed Aug 6, 2015
2 parents 7a07e11 + 099fb04 commit eaf753e
Showing 1 changed file with 14 additions and 41 deletions.
55 changes: 14 additions & 41 deletions system-test/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function deleteDocument(document, callback) {
}

function deleteIndexContents(index, callback) {
index.getDocuments(function(err, documents) {
index.getDocuments({ view: 'ID_ONLY' }, function(err, documents) {
if (err) {
callback(err);
return;
Expand All @@ -44,17 +44,6 @@ function deleteIndexContents(index, callback) {
});
}

function deleteAllDocuments(callback) {
search.getIndexes(function(err, indexes) {
if (err) {
callback(err);
return;
}

async.eachLimit(indexes, MAX_PARALLEL, deleteIndexContents, callback);
});
}

function generateIndexName() {
return 'gcloud-test-index-' + uuid.v1();
}
Expand All @@ -67,12 +56,8 @@ describe('Search', function() {
var INDEX_NAME = generateIndexName();
var index = search.index(INDEX_NAME);

before(function(done) {
deleteAllDocuments(done);
});

after(function(done) {
deleteAllDocuments(done);
deleteIndexContents(index, done);
});

describe('creating an index', function() {
Expand Down Expand Up @@ -140,21 +125,15 @@ describe('Search', function() {
var document;

before(function(done) {
async.series([
deleteAllDocuments,

function(next) {
index.createDocument(TEST_DOCUMENT_JSON, function(err, doc) {
if (err) {
next(err);
return;
}

document = doc;
next();
});
index.createDocument(TEST_DOCUMENT_JSON, function(err, doc) {
if (err) {
done(err);
return;
}
], done);

document = doc;
done();
});
});

after(function(done) {
Expand All @@ -169,14 +148,6 @@ describe('Search', function() {
});
});

it('should get all documents with autoPaginate', function(done) {
index.getDocuments({ autoPaginate: true }, function(err, documents) {
assert.ifError(err);
assert.strictEqual(documents.length, 1);
done();
});
});

it('should get all documents in stream mode', function(done) {
var resultsMatched = 0;

Expand Down Expand Up @@ -228,7 +199,8 @@ describe('Search', function() {
document.getMetadata(function(err) {
assert.ifError(err);
assert.deepEqual(document.toJSON(), TEST_DOCUMENT_JSON);
done();

document.delete(done);
});
});
});
Expand All @@ -239,7 +211,8 @@ describe('Search', function() {
document.getMetadata(function(err) {
assert.ifError(err);
assert.deepEqual(document.toJSON(), TEST_DOCUMENT_JSON);
done();

document.delete(done);
});
});
});
Expand Down

0 comments on commit eaf753e

Please sign in to comment.