Skip to content

Commit

Permalink
Getting datastore tests running on CI.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmdobry committed Nov 17, 2015
1 parent f10409c commit 5d4a5ec
Show file tree
Hide file tree
Showing 8 changed files with 337 additions and 294 deletions.
47 changes: 37 additions & 10 deletions datastore/concepts.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,17 @@ var datastore = {
save: function() {}
};

var keyFile = process.env.DATASTORE_KEYFILE || process.env.TEST_KEYFILE;

function Entity(projectId) {
this.datastore = gcloud.datastore({
var options = {
projectId: projectId
});
};

if (keyFile) {
options.keyFilename = keyFile;
}
this.datastore = gcloud.datastore(options);

// To create the keys, we have to use this instance of Datastore.
datastore.key = this.datastore.key;
Expand Down Expand Up @@ -437,9 +444,14 @@ Entity.prototype.testBatchDelete = function(callback) {
};

function Index(projectId) {
this.datastore = gcloud.datastore({
var options = {
projectId: projectId
});
};

if (keyFile) {
options.keyFilename = keyFile;
}
this.datastore = gcloud.datastore(options);
}

Index.prototype.testUnindexedPropertyQuery = function(callback) {
Expand Down Expand Up @@ -481,9 +493,14 @@ Index.prototype.testExplodingProperties = function(callback) {
};

function Metadata(projectId) {
this.datastore = gcloud.datastore({
var options = {
projectId: projectId
});
};

if (keyFile) {
options.keyFilename = keyFile;
}
this.datastore = gcloud.datastore(options);
}

Metadata.prototype.testNamespaceRunQuery = function(callback) {
Expand Down Expand Up @@ -614,9 +631,14 @@ Metadata.prototype.testPropertyByKindRunQuery = function(callback) {
};

function Query(projectId) {
this.datastore = gcloud.datastore({
var options = {
projectId: projectId
});
};

if (keyFile) {
options.keyFilename = keyFile;
}
this.datastore = gcloud.datastore(options);

this.basicQuery = this.getBasicQuery();
this.projectionQuery = this.getProjectionQuery();
Expand Down Expand Up @@ -1039,9 +1061,14 @@ function transferFunds(fromKey, toKey, amount, callback) {
// [END transactional_update]

function Transaction(projectId) {
this.datastore = gcloud.datastore({
var options = {
projectId: projectId
});
};

if (keyFile) {
options.keyFilename = keyFile;
}
this.datastore = gcloud.datastore(options);

this.fromKey = this.datastore.key(['Bank', 1, 'Account', 1]);
this.toKey = this.datastore.key(['Bank', 1, 'Account', 2]);
Expand Down
32 changes: 21 additions & 11 deletions datastore/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,17 @@ var projectId = process.env.DATASTORE_PROJECT_ID || process.env.TEST_PROJECT_ID;
if (!projectId) {
throw new Error('TEST_PROJECT_ID environment variable required.');
}
var keyFile = process.env.DATASTORE_KEYFILE || process.env.TEST_KEYFILE;

var datastore = gcloud.datastore({
var options = {
projectId: projectId
});
};

if (keyFile) {
options.keyFilename = keyFile;
}

var datastore = gcloud.datastore(options);

/*
// [START build_service]
Expand Down Expand Up @@ -216,19 +223,22 @@ switch (command) {
}

default: {
console.log([
'Usage:',
'',
' new <description> Adds a task with a description <description>',
' done <task-id> Marks a task as done',
' list Lists all tasks by creation time',
' delete <task-id> Deletes a task'
].join('\n'));
// Only print usage if this file is being executed directly
if (module === require.main) {
console.log([
'Usage:',
'',
' new <description> Adds a task with a description <description>',
' done <task-id> Marks a task as done',
' list Lists all tasks by creation time',
' delete <task-id> Deletes a task'
].join('\n'));
}
}
}

module.exports.addEntity = addTask;
module.exports.updateEntity = markDone;
module.exports.retrieveEntities = listTasks;
module.exports.deleteEntity = deleteTask;
module.exports.formatResults = formatTasks;
module.exports.formatTasks = formatTasks;
136 changes: 69 additions & 67 deletions test/datastore/entity.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,103 +16,105 @@
var Entity = require('../../datastore/concepts').Entity;
var entity;

before(function() {
var projectId = process.env.TEST_PROJECT_ID || 'nodejs-docs-samples';
entity = new Entity(projectId);
});
describe('datastore/concepts/entity', function () {
before(function() {
var projectId = process.env.TEST_PROJECT_ID || 'nodejs-docs-samples';
entity = new Entity(projectId);
});

describe('incomplete key', function() {
it('saves with an incomplete key', function(done) {
entity.testIncompleteKey(done);
describe('incomplete key', function() {
it('saves with an incomplete key', function(done) {
entity.testIncompleteKey(done);
});
});
});

describe('testNamedKey', function() {
it('saves with a named key', function(done) {
entity.testNamedKey(done);
describe('testNamedKey', function() {
it('saves with a named key', function(done) {
entity.testNamedKey(done);
});
});
});

describe('testKeyWithParent', function() {
it('saves a key with a parent', function(done) {
entity.testKeyWithParent(done);
describe('testKeyWithParent', function() {
it('saves a key with a parent', function(done) {
entity.testKeyWithParent(done);
});
});
});

describe('testKeyWithMultiLevelParent', function() {
it('saves a key with multiple parents', function(done) {
entity.testKeyWithMultiLevelParent(done);
describe('testKeyWithMultiLevelParent', function() {
it('saves a key with multiple parents', function(done) {
entity.testKeyWithMultiLevelParent(done);
});
});
});

describe('testEntityWithParent', function() {
it('saves an entity with a parent', function(done) {
entity.testEntityWithParent(done);
describe('testEntityWithParent', function() {
it('saves an entity with a parent', function(done) {
entity.testEntityWithParent(done);
});
});
});

describe('testProperties', function() {
it('saves an entity with properties', function(done) {
entity.testProperties(done);
describe('testProperties', function() {
it('saves an entity with properties', function(done) {
entity.testProperties(done);
});
});
});

describe('testArrayValue', function() {
it('saves an entity with arrays', function(done) {
entity.testArrayValue(done);
describe('testArrayValue', function() {
it('saves an entity with arrays', function(done) {
entity.testArrayValue(done);
});
});
});

describe('testBasicEntity', function() {
it('saves a basic entity', function(done) {
entity.testBasicEntity(done);
describe('testBasicEntity', function() {
it('saves a basic entity', function(done) {
entity.testBasicEntity(done);
});
});
});

describe('testUpsert', function() {
it('saves with an upsert', function(done) {
entity.testUpsert(done);
describe('testUpsert', function() {
it('saves with an upsert', function(done) {
entity.testUpsert(done);
});
});
});

describe('testInsert', function() {
it('saves with an insert', function(done) {
entity.testInsert(done);
describe('testInsert', function() {
it('saves with an insert', function(done) {
entity.testInsert(done);
});
});
});

describe('testLookup', function() {
it('performs a lookup', function(done) {
entity.testLookup(done);
describe('testLookup', function() {
it('performs a lookup', function(done) {
entity.testLookup(done);
});
});
});

describe('testUpdate', function() {
it('saves with an update', function(done) {
entity.testUpdate(done);
describe('testUpdate', function() {
it('saves with an update', function(done) {
entity.testUpdate(done);
});
});
});

describe('testDelete', function() {
it('deletes an entity', function(done) {
entity.testDelete(done);
describe('testDelete', function() {
it('deletes an entity', function(done) {
entity.testDelete(done);
});
});
});

describe('testBatchUpsert', function() {
it('performs a batch upsert', function(done) {
entity.testBatchUpsert(done);
describe('testBatchUpsert', function() {
it('performs a batch upsert', function(done) {
entity.testBatchUpsert(done);
});
});
});

describe('testBatchLookup', function() {
it('performs a batch lookup', function(done) {
entity.testBatchLookup(done);
describe('testBatchLookup', function() {
it('performs a batch lookup', function(done) {
entity.testBatchLookup(done);
});
});
});

describe('testBatchDelete', function() {
it('performs a batch delete', function(done) {
entity.testBatchDelete(done);
describe('testBatchDelete', function() {
it('performs a batch delete', function(done) {
entity.testBatchDelete(done);
});
});
});
26 changes: 15 additions & 11 deletions test/datastore/indexes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,23 @@
var Index = require('../../datastore/concepts').Index;
var index;

before(function() {
var projectId = process.env.TEST_PROJECT_ID || 'nodejs-docs-samples';
index = new Index(projectId);
});
describe('datastore/concepts/indexes', function () {
before(function() {
var projectId = process.env.TEST_PROJECT_ID || 'nodejs-docs-samples';
index = new Index(projectId);
});

describe('unindexed properties', function() {
it('performs a query with a filter on an unindexed property', function(done) {
index.testUnindexedPropertyQuery(done);
describe('unindexed properties', function() {
it('performs a query with a filter on an unindexed property',
function(done) {
index.testUnindexedPropertyQuery(done);
}
);
});
});

describe('exploding properties', function() {
it('inserts arrays of data', function(done) {
index.testExplodingProperties(done);
describe('exploding properties', function() {
it('inserts arrays of data', function(done) {
index.testExplodingProperties(done);
});
});
});
Loading

0 comments on commit 5d4a5ec

Please sign in to comment.