Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting datastore tests running on CI. #30

Merged
merged 2 commits into from
Nov 19, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 38 additions & 10 deletions datastore/concepts.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,18 @@ var datastore = {
save: function() {}
};

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

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 @@ -427,9 +435,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 @@ -471,9 +484,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 @@ -604,9 +622,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 @@ -1029,9 +1052,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
34 changes: 22 additions & 12 deletions datastore/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,20 @@ 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.GOOGLE_APPLICATION_CREDENTIALS;

// [START build_service]
var gcloud = require('gcloud');

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

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

var datastore = gcloud.datastore(options);
// [END build_service]

/*
Expand Down Expand Up @@ -218,19 +225,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