From 90e3175630735a0b5737dcdc43c2f9d06ccd84c8 Mon Sep 17 00:00:00 2001 From: jwngr Date: Mon, 13 Apr 2015 12:10:56 -0700 Subject: [PATCH 1/2] Fixed bug in BigQuery's table.import() callback invocation --- lib/bigquery/table.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/bigquery/table.js b/lib/bigquery/table.js index 3e92bd5ca8c..e8a902244a8 100644 --- a/lib/bigquery/table.js +++ b/lib/bigquery/table.js @@ -632,7 +632,9 @@ Table.prototype.import = function(source, metadata, callback) { return fs.createReadStream(source) .pipe(this.createWriteStream(metadata)) .on('error', callback) - .on('complete', callback); + .on('complete', function(job) { + callback(null, job); + }); } var body = { From 285415ecb3ea24fba9ab8d513dd84d66c4b7f333 Mon Sep 17 00:00:00 2001 From: jwngr Date: Mon, 13 Apr 2015 12:23:02 -0700 Subject: [PATCH 2/2] Added test for table.import() callback invocation --- test/bigquery/table.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/test/bigquery/table.js b/test/bigquery/table.js index 30535c86979..ab074b8f257 100644 --- a/test/bigquery/table.js +++ b/test/bigquery/table.js @@ -698,16 +698,22 @@ describe('BigQuery/Table', function() { }, 'file.json'); it('should accept just a File and a callback', function(done) { + var mockJob = { id: 'foo' }; + table.createWriteStream = function() { var ws = new stream.Writable(); setImmediate(function() { - ws.emit('complete'); + ws.emit('complete', mockJob); ws.end(); }); return ws; }; - table.import(FILEPATH, done); + table.import(FILEPATH, function(error, job) { + assert.strictEqual(error, null); + assert.deepEqual(job, mockJob); + done(); + }); }); it('should return a stream when a string is given', function() {