Skip to content

Commit 5d4a5ec

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

File tree

8 files changed

+337
-294
lines changed

8 files changed

+337
-294
lines changed

datastore/concepts.js

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

39+
var keyFile = process.env.DATASTORE_KEYFILE || process.env.TEST_KEYFILE;
40+
3941
function Entity(projectId) {
40-
this.datastore = gcloud.datastore({
42+
var options = {
4143
projectId: projectId
42-
});
44+
};
45+
46+
if (keyFile) {
47+
options.keyFilename = keyFile;
48+
}
49+
this.datastore = gcloud.datastore(options);
4350

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

439446
function Index(projectId) {
440-
this.datastore = gcloud.datastore({
447+
var options = {
441448
projectId: projectId
442-
});
449+
};
450+
451+
if (keyFile) {
452+
options.keyFilename = keyFile;
453+
}
454+
this.datastore = gcloud.datastore(options);
443455
}
444456

445457
Index.prototype.testUnindexedPropertyQuery = function(callback) {
@@ -481,9 +493,14 @@ Index.prototype.testExplodingProperties = function(callback) {
481493
};
482494

483495
function Metadata(projectId) {
484-
this.datastore = gcloud.datastore({
496+
var options = {
485497
projectId: projectId
486-
});
498+
};
499+
500+
if (keyFile) {
501+
options.keyFilename = keyFile;
502+
}
503+
this.datastore = gcloud.datastore(options);
487504
}
488505

489506
Metadata.prototype.testNamespaceRunQuery = function(callback) {
@@ -614,9 +631,14 @@ Metadata.prototype.testPropertyByKindRunQuery = function(callback) {
614631
};
615632

616633
function Query(projectId) {
617-
this.datastore = gcloud.datastore({
634+
var options = {
618635
projectId: projectId
619-
});
636+
};
637+
638+
if (keyFile) {
639+
options.keyFilename = keyFile;
640+
}
641+
this.datastore = gcloud.datastore(options);
620642

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

10411063
function Transaction(projectId) {
1042-
this.datastore = gcloud.datastore({
1064+
var options = {
10431065
projectId: projectId
1044-
});
1066+
};
1067+
1068+
if (keyFile) {
1069+
options.keyFilename = keyFile;
1070+
}
1071+
this.datastore = gcloud.datastore(options);
10451072

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

datastore/tasks.js

+21-11
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,17 @@ 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 || process.env.TEST_KEYFILE;
2425

25-
var datastore = gcloud.datastore({
26+
var options = {
2627
projectId: projectId
27-
});
28+
};
29+
30+
if (keyFile) {
31+
options.keyFilename = keyFile;
32+
}
33+
34+
var datastore = gcloud.datastore(options);
2835

2936
/*
3037
// [START build_service]
@@ -216,19 +223,22 @@ switch (command) {
216223
}
217224

218225
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'));
226+
// Only print usage if this file is being executed directly
227+
if (module === require.main) {
228+
console.log([
229+
'Usage:',
230+
'',
231+
' new <description> Adds a task with a description <description>',
232+
' done <task-id> Marks a task as done',
233+
' list Lists all tasks by creation time',
234+
' delete <task-id> Deletes a task'
235+
].join('\n'));
236+
}
227237
}
228238
}
229239

230240
module.exports.addEntity = addTask;
231241
module.exports.updateEntity = markDone;
232242
module.exports.retrieveEntities = listTasks;
233243
module.exports.deleteEntity = deleteTask;
234-
module.exports.formatResults = formatTasks;
244+
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)