Skip to content

Commit eb7f40a

Browse files
committed
Getting datastore tests running on CI.
1 parent f10409c commit eb7f40a

File tree

8 files changed

+339
-294
lines changed

8 files changed

+339
-294
lines changed

datastore/concepts.js

+38-10
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,18 @@ var datastore = {
3636
save: function() {}
3737
};
3838

39+
var keyFile = process.env.DATASTORE_KEYFILE ||
40+
process.env.GOOGLE_APPLICATION_CREDENTIALS;
41+
3942
function Entity(projectId) {
40-
this.datastore = gcloud.datastore({
43+
var options = {
4144
projectId: projectId
42-
});
45+
};
46+
47+
if (keyFile) {
48+
options.keyFilename = keyFile;
49+
}
50+
this.datastore = gcloud.datastore(options);
4351

4452
// To create the keys, we have to use this instance of Datastore.
4553
datastore.key = this.datastore.key;
@@ -437,9 +445,14 @@ Entity.prototype.testBatchDelete = function(callback) {
437445
};
438446

439447
function Index(projectId) {
440-
this.datastore = gcloud.datastore({
448+
var options = {
441449
projectId: projectId
442-
});
450+
};
451+
452+
if (keyFile) {
453+
options.keyFilename = keyFile;
454+
}
455+
this.datastore = gcloud.datastore(options);
443456
}
444457

445458
Index.prototype.testUnindexedPropertyQuery = function(callback) {
@@ -481,9 +494,14 @@ Index.prototype.testExplodingProperties = function(callback) {
481494
};
482495

483496
function Metadata(projectId) {
484-
this.datastore = gcloud.datastore({
497+
var options = {
485498
projectId: projectId
486-
});
499+
};
500+
501+
if (keyFile) {
502+
options.keyFilename = keyFile;
503+
}
504+
this.datastore = gcloud.datastore(options);
487505
}
488506

489507
Metadata.prototype.testNamespaceRunQuery = function(callback) {
@@ -614,9 +632,14 @@ Metadata.prototype.testPropertyByKindRunQuery = function(callback) {
614632
};
615633

616634
function Query(projectId) {
617-
this.datastore = gcloud.datastore({
635+
var options = {
618636
projectId: projectId
619-
});
637+
};
638+
639+
if (keyFile) {
640+
options.keyFilename = keyFile;
641+
}
642+
this.datastore = gcloud.datastore(options);
620643

621644
this.basicQuery = this.getBasicQuery();
622645
this.projectionQuery = this.getProjectionQuery();
@@ -1039,9 +1062,14 @@ function transferFunds(fromKey, toKey, amount, callback) {
10391062
// [END transactional_update]
10401063

10411064
function Transaction(projectId) {
1042-
this.datastore = gcloud.datastore({
1065+
var options = {
10431066
projectId: projectId
1044-
});
1067+
};
1068+
1069+
if (keyFile) {
1070+
options.keyFilename = keyFile;
1071+
}
1072+
this.datastore = gcloud.datastore(options);
10451073

10461074
this.fromKey = this.datastore.key(['Bank', 1, 'Account', 1]);
10471075
this.toKey = this.datastore.key(['Bank', 1, 'Account', 2]);

datastore/tasks.js

+22-11
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,18 @@ var projectId = process.env.DATASTORE_PROJECT_ID || process.env.TEST_PROJECT_ID;
2121
if (!projectId) {
2222
throw new Error('TEST_PROJECT_ID environment variable required.');
2323
}
24+
var keyFile = process.env.DATASTORE_KEYFILE ||
25+
process.env.GOOGLE_APPLICATION_CREDENTIALS;
2426

25-
var datastore = gcloud.datastore({
27+
var options = {
2628
projectId: projectId
27-
});
29+
};
30+
31+
if (keyFile) {
32+
options.keyFilename = keyFile;
33+
}
34+
35+
var datastore = gcloud.datastore(options);
2836

2937
/*
3038
// [START build_service]
@@ -216,19 +224,22 @@ switch (command) {
216224
}
217225

218226
default: {
219-
console.log([
220-
'Usage:',
221-
'',
222-
' new <description> Adds a task with a description <description>',
223-
' done <task-id> Marks a task as done',
224-
' list Lists all tasks by creation time',
225-
' delete <task-id> Deletes a task'
226-
].join('\n'));
227+
// Only print usage if this file is being executed directly
228+
if (module === require.main) {
229+
console.log([
230+
'Usage:',
231+
'',
232+
' new <description> Adds a task with a description <description>',
233+
' done <task-id> Marks a task as done',
234+
' list Lists all tasks by creation time',
235+
' delete <task-id> Deletes a task'
236+
].join('\n'));
237+
}
227238
}
228239
}
229240

230241
module.exports.addEntity = addTask;
231242
module.exports.updateEntity = markDone;
232243
module.exports.retrieveEntities = listTasks;
233244
module.exports.deleteEntity = deleteTask;
234-
module.exports.formatResults = formatTasks;
245+
module.exports.formatTasks = formatTasks;

test/datastore/entity.test.js

+69-67
Original file line numberDiff line numberDiff line change
@@ -16,103 +16,105 @@
1616
var Entity = require('../../datastore/concepts').Entity;
1717
var entity;
1818

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

24-
describe('incomplete key', function() {
25-
it('saves with an incomplete key', function(done) {
26-
entity.testIncompleteKey(done);
25+
describe('incomplete key', function() {
26+
it('saves with an incomplete key', function(done) {
27+
entity.testIncompleteKey(done);
28+
});
2729
});
28-
});
2930

30-
describe('testNamedKey', function() {
31-
it('saves with a named key', function(done) {
32-
entity.testNamedKey(done);
31+
describe('testNamedKey', function() {
32+
it('saves with a named key', function(done) {
33+
entity.testNamedKey(done);
34+
});
3335
});
34-
});
3536

36-
describe('testKeyWithParent', function() {
37-
it('saves a key with a parent', function(done) {
38-
entity.testKeyWithParent(done);
37+
describe('testKeyWithParent', function() {
38+
it('saves a key with a parent', function(done) {
39+
entity.testKeyWithParent(done);
40+
});
3941
});
40-
});
4142

42-
describe('testKeyWithMultiLevelParent', function() {
43-
it('saves a key with multiple parents', function(done) {
44-
entity.testKeyWithMultiLevelParent(done);
43+
describe('testKeyWithMultiLevelParent', function() {
44+
it('saves a key with multiple parents', function(done) {
45+
entity.testKeyWithMultiLevelParent(done);
46+
});
4547
});
46-
});
4748

48-
describe('testEntityWithParent', function() {
49-
it('saves an entity with a parent', function(done) {
50-
entity.testEntityWithParent(done);
49+
describe('testEntityWithParent', function() {
50+
it('saves an entity with a parent', function(done) {
51+
entity.testEntityWithParent(done);
52+
});
5153
});
52-
});
5354

54-
describe('testProperties', function() {
55-
it('saves an entity with properties', function(done) {
56-
entity.testProperties(done);
55+
describe('testProperties', function() {
56+
it('saves an entity with properties', function(done) {
57+
entity.testProperties(done);
58+
});
5759
});
58-
});
5960

60-
describe('testArrayValue', function() {
61-
it('saves an entity with arrays', function(done) {
62-
entity.testArrayValue(done);
61+
describe('testArrayValue', function() {
62+
it('saves an entity with arrays', function(done) {
63+
entity.testArrayValue(done);
64+
});
6365
});
64-
});
6566

66-
describe('testBasicEntity', function() {
67-
it('saves a basic entity', function(done) {
68-
entity.testBasicEntity(done);
67+
describe('testBasicEntity', function() {
68+
it('saves a basic entity', function(done) {
69+
entity.testBasicEntity(done);
70+
});
6971
});
70-
});
7172

72-
describe('testUpsert', function() {
73-
it('saves with an upsert', function(done) {
74-
entity.testUpsert(done);
73+
describe('testUpsert', function() {
74+
it('saves with an upsert', function(done) {
75+
entity.testUpsert(done);
76+
});
7577
});
76-
});
7778

78-
describe('testInsert', function() {
79-
it('saves with an insert', function(done) {
80-
entity.testInsert(done);
79+
describe('testInsert', function() {
80+
it('saves with an insert', function(done) {
81+
entity.testInsert(done);
82+
});
8183
});
82-
});
8384

84-
describe('testLookup', function() {
85-
it('performs a lookup', function(done) {
86-
entity.testLookup(done);
85+
describe('testLookup', function() {
86+
it('performs a lookup', function(done) {
87+
entity.testLookup(done);
88+
});
8789
});
88-
});
8990

90-
describe('testUpdate', function() {
91-
it('saves with an update', function(done) {
92-
entity.testUpdate(done);
91+
describe('testUpdate', function() {
92+
it('saves with an update', function(done) {
93+
entity.testUpdate(done);
94+
});
9395
});
94-
});
9596

96-
describe('testDelete', function() {
97-
it('deletes an entity', function(done) {
98-
entity.testDelete(done);
97+
describe('testDelete', function() {
98+
it('deletes an entity', function(done) {
99+
entity.testDelete(done);
100+
});
99101
});
100-
});
101102

102-
describe('testBatchUpsert', function() {
103-
it('performs a batch upsert', function(done) {
104-
entity.testBatchUpsert(done);
103+
describe('testBatchUpsert', function() {
104+
it('performs a batch upsert', function(done) {
105+
entity.testBatchUpsert(done);
106+
});
105107
});
106-
});
107108

108-
describe('testBatchLookup', function() {
109-
it('performs a batch lookup', function(done) {
110-
entity.testBatchLookup(done);
109+
describe('testBatchLookup', function() {
110+
it('performs a batch lookup', function(done) {
111+
entity.testBatchLookup(done);
112+
});
111113
});
112-
});
113114

114-
describe('testBatchDelete', function() {
115-
it('performs a batch delete', function(done) {
116-
entity.testBatchDelete(done);
115+
describe('testBatchDelete', function() {
116+
it('performs a batch delete', function(done) {
117+
entity.testBatchDelete(done);
118+
});
117119
});
118120
});

test/datastore/indexes.test.js

+15-11
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,23 @@
1616
var Index = require('../../datastore/concepts').Index;
1717
var index;
1818

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

24-
describe('unindexed properties', function() {
25-
it('performs a query with a filter on an unindexed property', function(done) {
26-
index.testUnindexedPropertyQuery(done);
25+
describe('unindexed properties', function() {
26+
it('performs a query with a filter on an unindexed property',
27+
function(done) {
28+
index.testUnindexedPropertyQuery(done);
29+
}
30+
);
2731
});
28-
});
2932

30-
describe('exploding properties', function() {
31-
it('inserts arrays of data', function(done) {
32-
index.testExplodingProperties(done);
33+
describe('exploding properties', function() {
34+
it('inserts arrays of data', function(done) {
35+
index.testExplodingProperties(done);
36+
});
3337
});
3438
});

0 commit comments

Comments
 (0)