Skip to content

Commit 069d827

Browse files
stephenpluspluscallmehiphop
authored andcommitted
bigquery/language/logging/prediction/vision: decouple packages (#1531)
* bigquery/language/logging/prediction/vision: decouple packages * tests: allow more time for docs tests to run * add vision test * resort dependencies like npm does
1 parent 137efae commit 069d827

25 files changed

Lines changed: 257 additions & 131 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"docs": "node ./scripts/docs/packages.js",
3030
"bundle": "node ./scripts/docs/bundle.js",
3131
"lint": "jshint scripts/ packages/ system-test/ test/ && jscs packages/ system-test/ test/",
32-
"test": "npm run docs && npm run bundle && mocha test/docs.js packages/*/test/*.js",
32+
"test": "npm run docs && npm run bundle && mocha --timeout 5000 test/docs.js packages/*/test/*.js",
3333
"system-test": "mocha packages/*/system-test/*.js --no-timeouts --bail",
3434
"cover": "istanbul cover _mocha --report lcovonly -x 'packages/*/src/v*/*.js' -- --no-timeouts --bail packages/*/test/*.js -R spec",
3535
"coveralls": "npm run cover && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage"

packages/bigquery/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,17 @@
5050
"bigquery"
5151
],
5252
"dependencies": {
53+
"@google-cloud/common": "^0.3.0",
5354
"arrify": "^1.0.0",
5455
"duplexify": "^3.2.0",
5556
"extend": "^3.0.0",
56-
"@google-cloud/common": "^0.1.0",
57-
"@google-cloud/storage": "^0.1.0",
5857
"is": "^3.0.1",
5958
"modelo": "^4.2.0",
6059
"stream-events": "^1.0.1",
6160
"string-format-obj": "^1.0.0"
6261
},
6362
"devDependencies": {
63+
"@google-cloud/storage": "*",
6464
"async": "^1.4.2",
6565
"mocha": "^3.0.1",
6666
"node-uuid": "^1.4.3",

packages/bigquery/src/table.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ var format = require('string-format-obj');
2828
var fs = require('fs');
2929
var is = require('is');
3030
var path = require('path');
31-
var Storage = require('@google-cloud/storage');
3231
var streamEvents = require('stream-events');
3332
var util = require('util');
3433

@@ -504,7 +503,7 @@ Table.prototype.export = function(destination, options, callback) {
504503

505504
extend(true, options, {
506505
destinationUris: arrify(destination).map(function(dest) {
507-
if (!(dest instanceof Storage.File)) {
506+
if (!common.util.isCustomType(dest, 'storage/file')) {
508507
throw new Error('Destination must be a File object.');
509508
}
510509

@@ -787,7 +786,7 @@ Table.prototype.import = function(source, metadata, callback) {
787786

788787
extend(true, body.configuration.load, metadata, {
789788
sourceUris: arrify(source).map(function(src) {
790-
if (!(src instanceof Storage.File)) {
789+
if (!common.util.isCustomType(src, 'storage/file')) {
791790
throw new Error('Source must be a File object.');
792791
}
793792

packages/bigquery/test/table.js

Lines changed: 62 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,17 @@ var prop = require('propprop');
2424
var proxyquire = require('proxyquire');
2525
var stream = require('stream');
2626

27-
var File = require('@google-cloud/storage').File;
2827
var ServiceObject = require('@google-cloud/common').ServiceObject;
2928
var util = require('@google-cloud/common').util;
3029

31-
function FakeFile(a, b) {
32-
this.request = util.noop;
33-
File.call(this, a, b);
34-
}
35-
3630
var makeWritableStreamOverride;
31+
var isCustomTypeOverride;
3732
var fakeUtil = extend({}, util, {
33+
isCustomType: function() {
34+
return (isCustomTypeOverride || util.isCustomType).apply(null, arguments);
35+
},
3836
makeWritableStream: function() {
39-
var args = [].slice.call(arguments);
37+
var args = arguments;
4038
(makeWritableStreamOverride || util.makeWritableStream).apply(null, args);
4139
}
4240
});
@@ -70,7 +68,8 @@ describe('BigQuery/Table', function() {
7068
projectId: 'project-id',
7169
job: function(id) {
7270
return { id: id };
73-
}
71+
},
72+
request: util.noop
7473
}
7574
};
7675

@@ -98,9 +97,6 @@ describe('BigQuery/Table', function() {
9897

9998
before(function() {
10099
Table = proxyquire('../src/table.js', {
101-
'@google-cloud/storage': {
102-
File: FakeFile
103-
},
104100
'@google-cloud/common': {
105101
ServiceObject: FakeServiceObject,
106102
streamRouter: fakeStreamRouter,
@@ -125,9 +121,11 @@ describe('BigQuery/Table', function() {
125121
});
126122

127123
beforeEach(function() {
124+
isCustomTypeOverride = null;
128125
makeWritableStreamOverride = null;
129126
tableOverrides = {};
130127
table = new Table(DATASET, TABLE_ID);
128+
table.bigQuery.request = util.noop;
131129
});
132130

133131
describe('instantiation', function() {
@@ -480,12 +478,18 @@ describe('BigQuery/Table', function() {
480478
});
481479

482480
describe('export', function() {
483-
var FILE = new FakeFile({
484-
name: 'bucket-name',
485-
makeReq_: util.noop,
486-
}, 'file.json');
481+
var FILE = {
482+
name: 'file-name.json',
483+
bucket: {
484+
name: 'bucket-name'
485+
}
486+
};
487487

488488
beforeEach(function() {
489+
isCustomTypeOverride = function() {
490+
return true;
491+
};
492+
489493
table.bigQuery.job = function(id) {
490494
return { id: id };
491495
};
@@ -555,10 +559,25 @@ describe('BigQuery/Table', function() {
555559
done();
556560
};
557561

558-
table.export(FILE, done);
562+
table.export(FILE, assert.ifError);
563+
});
564+
565+
it('should check if a destination is a File', function(done) {
566+
isCustomTypeOverride = function(dest, type) {
567+
assert.strictEqual(dest, FILE);
568+
assert.strictEqual(type, 'storage/file');
569+
setImmediate(done);
570+
return true;
571+
};
572+
573+
table.export(FILE, assert.ifError);
559574
});
560575

561576
it('should throw if a destination is not a File', function() {
577+
isCustomTypeOverride = function() {
578+
return false;
579+
};
580+
562581
assert.throws(function() {
563582
table.export({}, util.noop);
564583
}, /Destination must be a File object/);
@@ -794,10 +813,18 @@ describe('BigQuery/Table', function() {
794813

795814
describe('import', function() {
796815
var FILEPATH = require.resolve('./testdata/testfile.json');
797-
var FILE = new FakeFile({
798-
name: 'bucket-name',
799-
makeReq_: util.noop
800-
}, 'file.json');
816+
var FILE = {
817+
name: 'file-name.json',
818+
bucket: {
819+
name: 'bucket-name'
820+
}
821+
};
822+
823+
beforeEach(function() {
824+
isCustomTypeOverride = function() {
825+
return true;
826+
};
827+
});
801828

802829
it('should accept just a File and a callback', function(done) {
803830
var mockJob = { id: 'foo' };
@@ -873,7 +900,22 @@ describe('BigQuery/Table', function() {
873900
table.import(FILEPATH, { sourceFormat: 'CSV' }, done);
874901
});
875902

903+
it('should check if a destination is a File', function(done) {
904+
isCustomTypeOverride = function(dest, type) {
905+
assert.strictEqual(dest, FILE);
906+
assert.strictEqual(type, 'storage/file');
907+
setImmediate(done);
908+
return true;
909+
};
910+
911+
table.export(FILE, assert.ifError);
912+
});
913+
876914
it('should throw if a File object is not provided', function() {
915+
isCustomTypeOverride = function() {
916+
return false;
917+
};
918+
877919
assert.throws(function() {
878920
table.import({});
879921
}, /Source must be a File object/);

packages/bigtable/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@
5050
"bigtable"
5151
],
5252
"dependencies": {
53+
"@google-cloud/common": "^0.1.0",
5354
"arrify": "^1.0.0",
5455
"concat-stream": "^1.5.0",
5556
"create-error-class": "^2.0.1",
5657
"dot-prop": "^2.4.0",
5758
"extend": "^3.0.0",
58-
"@google-cloud/common": "^0.1.0",
5959
"google-proto-files": "^0.2.1",
6060
"is": "^3.0.1",
6161
"lodash.flatten": "^4.2.0",

packages/compute/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@
5050
"compute engine"
5151
],
5252
"dependencies": {
53+
"@google-cloud/common": "^0.1.0",
5354
"arrify": "^1.0.0",
5455
"async": "^1.4.2",
5556
"create-error-class": "^2.0.1",
5657
"extend": "^3.0.0",
5758
"gce-images": "^0.3.0",
58-
"@google-cloud/common": "^0.1.0",
5959
"is": "^3.0.1",
6060
"modelo": "^4.2.0",
6161
"string-format-obj": "^1.0.0"

packages/datastore/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@
5050
"datastore"
5151
],
5252
"dependencies": {
53+
"@google-cloud/common": "^0.2.0",
5354
"arrify": "^1.0.0",
5455
"concat-stream": "^1.5.0",
5556
"create-error-class": "^2.0.1",
5657
"extend": "^3.0.0",
57-
"@google-cloud/common": "^0.2.0",
5858
"is": "^3.0.1",
5959
"lodash.flatten": "^4.2.0",
6060
"modelo": "^4.2.0",

packages/dns/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@
5050
"dns"
5151
],
5252
"dependencies": {
53+
"@google-cloud/common": "^0.1.0",
5354
"arrify": "^1.0.0",
5455
"dns-zonefile": "0.1.18",
5556
"extend": "^3.0.0",
56-
"@google-cloud/common": "^0.1.0",
5757
"is": "^3.0.1",
5858
"methmeth": "^1.0.0",
5959
"string-format-obj": "^1.0.0"

packages/google-cloud/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@
9393
"vision"
9494
],
9595
"dependencies": {
96-
"extend": "^3.0.0",
9796
"@google-cloud/bigquery": "^0.1.1",
9897
"@google-cloud/bigtable": "^0.1.1",
9998
"@google-cloud/compute": "^0.1.1",
@@ -106,7 +105,8 @@
106105
"@google-cloud/resource": "^0.1.1",
107106
"@google-cloud/storage": "^0.1.1",
108107
"@google-cloud/translate": "^0.1.1",
109-
"@google-cloud/vision": "^0.1.1"
108+
"@google-cloud/vision": "^0.1.1",
109+
"extend": "^3.0.0"
110110
},
111111
"devDependencies": {
112112
"proxyquire": "^1.7.10"

packages/language/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@
5252
"language"
5353
],
5454
"dependencies": {
55-
"@google-cloud/common": "^0.1.0",
56-
"@google-cloud/storage": "^0.1.0",
55+
"@google-cloud/common": "^0.3.0",
5756
"arguejs": "^0.2.3",
5857
"arrify": "^1.0.1",
5958
"extend": "^3.0.0",
@@ -64,6 +63,7 @@
6463
"string-format-obj": "^1.0.0"
6564
},
6665
"devDependencies": {
66+
"@google-cloud/storage": "*",
6767
"mocha": "^2.1.0",
6868
"node-uuid": "^1.4.7",
6969
"proxyquire": "^1.7.10",

0 commit comments

Comments
 (0)