Skip to content

Commit 2997fe7

Browse files
author
Ace Nassri
committed
Move from gcloud to google-cloud/bigquery
1 parent f7065fd commit 2997fe7

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

bigquery/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"system-test": "mocha -R spec -t 120000 --require intelli-espower-loader ../system-test/_setup.js system-test/*.test.js"
1010
},
1111
"dependencies": {
12+
"@google-cloud/bigquery": "^0.1.1",
1213
"async": "^1.5.2",
1314
"gcloud": "^0.37.0",
1415
"request": "^2.72.0"

bigquery/query.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
// by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use the
2828
// project specified by the GCLOUD_PROJECT environment variable. See
2929
// https://googlecloudplatform.github.io/gcloud-node/#/docs/guides/authentication
30-
var gcloud = require('gcloud');
30+
var BigQuery = require('@google-cloud/bigquery');
3131

3232
// Instantiate the bigquery client
33-
var bigquery = gcloud.bigquery();
33+
var bigquery = BigQuery();
3434
// [END auth]
3535

3636
// [START sync_query]

bigquery/test/query.test.js

+9-6
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ function getSample () {
2424
{ year: '2005' }
2525
];
2626

27+
var BigQuery = require('@google-cloud/bigquery');
28+
2729
var metadataMock = { status: { state: 'DONE' } };
2830

2931
var jobId = 'abc';
@@ -39,15 +41,15 @@ function getSample () {
3941
startQuery: sinon.stub().callsArgWith(1, null, jobMock),
4042
query: sinon.stub().callsArgWith(1, null, natalityMock)
4143
};
42-
var gcloudMock = {
43-
bigquery: sinon.stub().returns(bigqueryMock)
44-
};
44+
45+
var BigQueryMock = sinon.stub().returns(bigqueryMock);
46+
4547
return {
4648
program: proxyquire('../query', {
47-
gcloud: gcloudMock
49+
'@google-cloud/bigquery': BigQueryMock
4850
}),
4951
mocks: {
50-
gcloud: gcloudMock,
52+
BigQuery: BigQueryMock,
5153
bigquery: bigqueryMock,
5254
natality: natalityMock,
5355
metadata: metadataMock,
@@ -215,8 +217,8 @@ describe('bigquery:query', function () {
215217
example.mocks.job.getMetadata = sinon.stub().callsArgWith(0, null, pendingState);
216218
example.program.asyncPoll(example.jobId, function (err, rows) {
217219
assert.deepEqual(err, Error('Job %s is not done', example.jobId));
218-
assert(example.mocks.job.getMetadata.called);
219220
assert(console.log.calledWith('Job status: %s', pendingState.status.state));
221+
assert(example.mocks.job.getMetadata.called);
220222
assert.equal(example.mocks.job.getQueryResults.called, false);
221223
assert.equal(rows, undefined);
222224
});
@@ -228,6 +230,7 @@ describe('bigquery:query', function () {
228230
assert(console.log.calledWith('Job status: %s', doneState.status.state));
229231
assert(example.mocks.job.getMetadata.called);
230232
assert(example.mocks.job.getQueryResults.called);
233+
assert.equal(rows, example.mocks.natality);
231234
});
232235
});
233236

0 commit comments

Comments
 (0)