Skip to content

Commit

Permalink
Merge pull request #496 from jwngr/jw-table-import-bug
Browse files Browse the repository at this point in the history
Fixed bug in BigQuery's table.import() callback invocation
  • Loading branch information
ryanseys committed Apr 13, 2015
2 parents f9cab1e + 285415e commit 0779b27
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/bigquery/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
10 changes: 8 additions & 2 deletions test/bigquery/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 0779b27

Please sign in to comment.