Skip to content

Commit ccd85bd

Browse files
committed
more test refactoring
1 parent 7b95daf commit ccd85bd

5 files changed

Lines changed: 87 additions & 72 deletions

File tree

system-test/bigtable.js

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,7 @@ function generateTableName() {
200200
});
201201

202202
it('should delete a column family', function(done) {
203-
FAMILY.delete(function(err) {
204-
assert.ifError(err);
205-
done();
206-
});
203+
FAMILY.delete(done);
207204
});
208205

209206
});
@@ -260,10 +257,7 @@ function generateTableName() {
260257
}
261258
};
262259

263-
row.create(rowData, function(err) {
264-
assert.ifError(err);
265-
done();
266-
});
260+
row.create(rowData, done);
267261
});
268262

269263
it('should insert individual cells', function(done) {
@@ -275,10 +269,7 @@ function generateTableName() {
275269
}
276270
};
277271

278-
row.save(rowData, function(err) {
279-
assert.ifError(err);
280-
done();
281-
});
272+
row.save(rowData, done);
282273
});
283274

284275
it('should allow for user specified timestamps', function(done) {
@@ -293,10 +284,7 @@ function generateTableName() {
293284
}
294285
};
295286

296-
row.save(rowData, function(err) {
297-
assert.ifError(err);
298-
done();
299-
});
287+
row.save(rowData, done);
300288
});
301289

302290
it('should increment a column value', function(done) {
@@ -688,40 +676,30 @@ function generateTableName() {
688676
it('should delete specific cells', function(done) {
689677
var row = TABLE.row('alincoln');
690678

691-
row.deleteCells(['follows:gwashington'], function(err) {
692-
assert.ifError(err);
693-
done();
694-
});
679+
row.deleteCells(['follows:gwashington'], done);
695680
});
696681

697682
it('should delete a family', function(done) {
698683
var row = TABLE.row('gwashington');
699684

700-
row.deleteCells(['traits'], function(err) {
701-
assert.ifError(err);
702-
done();
703-
});
685+
row.deleteCells(['traits'], done);
704686
});
705687

706688
it('should delete all the cells', function(done) {
707689
var row = TABLE.row('alincoln');
708690

709-
row.delete(function(err) {
710-
assert.ifError(err);
711-
done();
712-
});
691+
row.delete(done);
713692
});
714693

715694
it('should delete all the rows', function(done) {
716695
TABLE.deleteRows(function(err) {
717696
assert.ifError(err);
718697

719-
TABLE.getRows()
720-
.on('error', done)
721-
.on('data', function() {
722-
done(new Error('Row found!'));
723-
})
724-
.on('end', done);
698+
TABLE.getRows(function(err, rows) {
699+
assert.ifError(err);
700+
assert.strictEqual(rows.length, 0);
701+
done();
702+
});
725703
});
726704
});
727705

test/bigtable/filter.js

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -527,17 +527,22 @@ describe('Bigtable/Filter', function() {
527527
var value = {
528528
value: 'fake-value'
529529
};
530-
var convertedValue = 'abcd';
530+
var fakeRegExValue = 'abcd';
531+
var fakeConvertedValue = 'dcba';
531532

532-
var spy = sinon.stub(Filter, 'convertToRegExpString', function() {
533-
return convertedValue;
533+
var regSpy = sinon.stub(Filter, 'convertToRegExpString', function() {
534+
return fakeRegExValue;
535+
});
536+
537+
var bytesSpy = FakeMutation.convertToBytes = sinon.spy(function() {
538+
return fakeConvertedValue;
534539
});
535540

536541
filter.set = function(filterName, val) {
537542
assert.strictEqual(filterName, 'valueRegexFilter');
538-
assert.strictEqual(convertedValue, val);
539-
assert(spy.calledWithExactly(value.value));
540-
assert(FakeMutation.convertToBytes.calledWithExactly(convertedValue));
543+
assert.strictEqual(fakeConvertedValue, val);
544+
assert(regSpy.calledWithExactly(value.value));
545+
assert(bytesSpy.calledWithExactly(fakeRegExValue));
541546
done();
542547
};
543548

@@ -547,9 +552,22 @@ describe('Bigtable/Filter', function() {
547552
it('should accept the short-hand version of value', function(done) {
548553
var value = 'fake-value';
549554

555+
var fakeRegExValue = 'abcd';
556+
var fakeConvertedValue = 'dcba';
557+
558+
var regSpy = sinon.stub(Filter, 'convertToRegExpString', function() {
559+
return fakeRegExValue;
560+
});
561+
562+
var bytesSpy = FakeMutation.convertToBytes = sinon.spy(function() {
563+
return fakeConvertedValue;
564+
});
565+
550566
filter.set = function(filterName, val) {
551567
assert.strictEqual(filterName, 'valueRegexFilter');
552-
assert.strictEqual(val, value);
568+
assert.strictEqual(fakeConvertedValue, val);
569+
assert(regSpy.calledWithExactly(value));
570+
assert(bytesSpy.calledWithExactly(fakeRegExValue));
553571
done();
554572
};
555573

test/bigtable/index.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ describe('Bigtable', function() {
111111
});
112112

113113
it('should localize the cluster name', function() {
114-
assert(bigtable.clusterName, CLUSTER_NAME);
114+
assert.strictEqual(bigtable.clusterName, CLUSTER_NAME);
115115
});
116116

117117
it('should inherit from GrpcService', function() {
@@ -143,7 +143,7 @@ describe('Bigtable', function() {
143143
var fakeTableName = 'projects/p/zones/z/clusters/c/tables/my-table';
144144
var formatted = Bigtable.formatTableName_(fakeTableName);
145145

146-
assert(formatted, 'my-table');
146+
assert.strictEqual(formatted, 'my-table');
147147
});
148148

149149
it('should do nothing if the table is name is not formatted', function() {
@@ -222,13 +222,20 @@ describe('Bigtable', function() {
222222
name: TABLE_ID
223223
};
224224

225+
var fakeTable = {};
226+
227+
var tableSpy = sinon.stub(bigtable, 'table', function() {
228+
return fakeTable;
229+
});
230+
225231
bigtable.request = function(p, r, callback) {
226232
callback(null, response);
227233
};
228234

229235
bigtable.createTable(TABLE_ID, function(err, table, apiResponse) {
230236
assert.ifError(err);
231-
assert(table instanceof FakeTable);
237+
assert.strictEqual(table, fakeTable);
238+
assert(tableSpy.calledWithExactly(response.name));
232239
assert.strictEqual(table.metadata, response);
233240
assert.strictEqual(response, apiResponse);
234241
done();
@@ -273,15 +280,15 @@ describe('Bigtable', function() {
273280
name: 'projects/p/zones/z/clusters/c/tables/my-table'
274281
}]
275282
};
283+
var fakeTable = {};
276284

277285
bigtable.request = function(p, r, callback) {
278286
callback(null, response);
279287
};
280288

281-
bigtable.table = function(name) {
282-
assert.strictEqual(name, fakeFormattedName);
283-
return new FakeTable(bigtable, name);
284-
};
289+
var tableSpy = sinon.stub(bigtable, 'table', function() {
290+
return fakeTable;
291+
});
285292

286293
var formatSpy = sinon.stub(Bigtable, 'formatTableName_', function() {
287294
return fakeFormattedName;
@@ -292,14 +299,11 @@ describe('Bigtable', function() {
292299

293300
var table = tables[0];
294301

295-
assert(table instanceof FakeTable);
302+
assert.strictEqual(table, fakeTable);
303+
assert(formatSpy.calledWithExactly(response.tables[0].name));
304+
assert(tableSpy.calledWithExactly(fakeFormattedName));
296305
assert.strictEqual(table.metadata, response.tables[0]);
297306
assert.strictEqual(response, apiResponse);
298-
299-
var tableName = table.calledWith_[1];
300-
301-
assert.strictEqual(tableName, fakeFormattedName);
302-
assert(formatSpy.calledWithExactly(response.tables[0].name));
303307
done();
304308
});
305309
});

test/bigtable/mutation.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,17 @@ describe('Bigtable/Mutation', function() {
205205
}]);
206206
});
207207

208+
it('should array-ify the input', function() {
209+
var fakeKey = 'follows';
210+
var mutation = Mutation.encodeDelete(fakeKey);
211+
212+
assert.deepEqual(mutation, [{
213+
deleteFromFamily: {
214+
familyName: fakeKey
215+
}
216+
}]);
217+
});
218+
208219
it('should create a delete family mutation', function() {
209220
var fakeColumnName = {
210221
family: 'followed',
@@ -215,7 +226,7 @@ describe('Bigtable/Mutation', function() {
215226
return fakeColumnName;
216227
});
217228

218-
var mutation = Mutation.encodeDelete('follows');
229+
var mutation = Mutation.encodeDelete(['follows']);
219230

220231
assert.deepEqual(mutation, [{
221232
deleteFromFamily: {

test/bigtable/row.js

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,10 @@ describe('Bigtable/Row', function() {
119119
});
120120

121121
describe('formatChunks_', function() {
122-
var spy;
122+
var formatFamiliesSpy;
123123

124124
beforeEach(function() {
125-
spy = sinon.stub(Row, 'formatFamilies_');
125+
formatFamiliesSpy = sinon.stub(Row, 'formatFamilies_');
126126
});
127127

128128
it('should not include chunks without commitRow', function() {
@@ -131,13 +131,13 @@ describe('Bigtable/Row', function() {
131131
}];
132132
var fakeFamilies = [];
133133

134-
spy.returns(fakeFamilies);
134+
formatFamiliesSpy.returns(fakeFamilies);
135135

136136
var formatted = Row.formatChunks_(chunks);
137137

138138
assert.strictEqual(formatted, fakeFamilies);
139-
assert.strictEqual(spy.callCount, 1);
140-
assert.deepEqual(spy.getCall(0).args[0], []);
139+
assert.strictEqual(formatFamiliesSpy.callCount, 1);
140+
assert.deepEqual(formatFamiliesSpy.getCall(0).args[0], []);
141141
});
142142

143143
it('should ignore any chunks previous to a resetRow', function() {
@@ -155,14 +155,14 @@ describe('Bigtable/Row', function() {
155155
commitRow: true
156156
}];
157157

158-
spy.returns(fakeFamilies);
158+
formatFamiliesSpy.returns(fakeFamilies);
159159

160160
var formatted = Row.formatChunks_(chunks);
161161

162162
assert.strictEqual(formatted, fakeFamilies);
163163
assert.strictEqual(formatted.indexOf(badData), -1);
164-
assert.strictEqual(spy.callCount, 1);
165-
assert.deepEqual(spy.getCall(0).args[0], [goodData]);
164+
assert.strictEqual(formatFamiliesSpy.callCount, 1);
165+
assert.deepEqual(formatFamiliesSpy.getCall(0).args[0], [goodData]);
166166
});
167167
});
168168

@@ -193,11 +193,12 @@ describe('Bigtable/Row', function() {
193193

194194
it('should format the families into a user-friendly format', function() {
195195
var formatted = Row.formatFamilies_(families);
196-
197196
assert.deepEqual(formatted, formattedRowData);
198-
assert.strictEqual(FakeMutation.convertFromBytes.callCount, 2);
199-
assert(FakeMutation.convertFromBytes.getCall(0).args[0], 'test-column');
200-
assert(FakeMutation.convertFromBytes.getCall(1).args[0], 'test-value');
197+
198+
var convertStpy = FakeMutation.convertFromBytes;
199+
assert.strictEqual(convertStpy.callCount, 2);
200+
assert.strictEqual(convertStpy.getCall(0).args[0], 'test-column');
201+
assert.strictEqual(convertStpy.getCall(1).args[0], 'test-value');
201202
});
202203
});
203204

@@ -459,6 +460,7 @@ describe('Bigtable/Row', function() {
459460
it('should provide the proper request options', function(done) {
460461
row.parent.getRows = function(reqOpts) {
461462
assert.strictEqual(reqOpts.key, ROW_ID);
463+
assert.strictEqual(reqOpts.filter, undefined);
462464
assert.strictEqual(FakeMutation.parseColumnName.callCount, 0);
463465
done();
464466
};
@@ -565,6 +567,7 @@ describe('Bigtable/Row', function() {
565567

566568
row.get(function(err, row_, apiResponse) {
567569
assert(err instanceof Row.RowError);
570+
assert.strictEqual(err.message, 'Unknown row: ' + row.id + '.');
568571
assert.deepEqual(row_, null);
569572
assert.strictEqual(response, apiResponse);
570573
done();
@@ -661,10 +664,10 @@ describe('Bigtable/Row', function() {
661664

662665
describe('increment', function() {
663666
var COLUMN_NAME = 'a:b';
664-
var spy;
667+
var formatFamiliesSpy;
665668

666669
beforeEach(function() {
667-
spy = sinon.stub(Row, 'formatFamilies_').returns({
670+
formatFamiliesSpy = sinon.stub(Row, 'formatFamilies_').returns({
668671
a: {
669672
b: [{
670673
value: 10
@@ -736,8 +739,8 @@ describe('Bigtable/Row', function() {
736739
assert.ifError(err);
737740
assert.strictEqual(value, fakeValue);
738741
assert.strictEqual(apiResponse, response);
739-
assert.strictEqual(spy.callCount, 1);
740-
assert(spy.calledWithExactly(response.families));
742+
assert.strictEqual(formatFamiliesSpy.callCount, 1);
743+
assert(formatFamiliesSpy.calledWithExactly(response.families));
741744
done();
742745
});
743746
});
@@ -754,7 +757,7 @@ describe('Bigtable/Row', function() {
754757
}
755758
};
756759

757-
Mutation.parseColumnName = sinon.spy(function() {
760+
var parseSpy = Mutation.parseColumnName = sinon.spy(function() {
758761
return {
759762
family: 'd',
760763
qualifier: 'e'
@@ -765,6 +768,7 @@ describe('Bigtable/Row', function() {
765768
assert.strictEqual(entry.key, ROW_ID);
766769
assert.deepEqual(entry.data, expectedData);
767770
assert.strictEqual(entry.method, FakeMutation.methods.INSERT);
771+
assert(parseSpy.calledWithExactly(key));
768772
callback();
769773
};
770774

0 commit comments

Comments
 (0)