Skip to content

Commit

Permalink
bigquery/language/logging/prediction/vision: decouple packages (#1531)
Browse files Browse the repository at this point in the history
* bigquery/language/logging/prediction/vision: decouple packages

* tests: allow more time for docs tests to run

* add vision test

* resort dependencies like npm does
  • Loading branch information
stephenplusplus authored and callmehiphop committed Aug 26, 2016
1 parent 137efae commit 069d827
Show file tree
Hide file tree
Showing 25 changed files with 257 additions and 131 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"docs": "node ./scripts/docs/packages.js",
"bundle": "node ./scripts/docs/bundle.js",
"lint": "jshint scripts/ packages/ system-test/ test/ && jscs packages/ system-test/ test/",
"test": "npm run docs && npm run bundle && mocha test/docs.js packages/*/test/*.js",
"test": "npm run docs && npm run bundle && mocha --timeout 5000 test/docs.js packages/*/test/*.js",
"system-test": "mocha packages/*/system-test/*.js --no-timeouts --bail",
"cover": "istanbul cover _mocha --report lcovonly -x 'packages/*/src/v*/*.js' -- --no-timeouts --bail packages/*/test/*.js -R spec",
"coveralls": "npm run cover && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage"
Expand Down
4 changes: 2 additions & 2 deletions packages/bigquery/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,17 @@
"bigquery"
],
"dependencies": {
"@google-cloud/common": "^0.3.0",
"arrify": "^1.0.0",
"duplexify": "^3.2.0",
"extend": "^3.0.0",
"@google-cloud/common": "^0.1.0",
"@google-cloud/storage": "^0.1.0",
"is": "^3.0.1",
"modelo": "^4.2.0",
"stream-events": "^1.0.1",
"string-format-obj": "^1.0.0"
},
"devDependencies": {
"@google-cloud/storage": "*",
"async": "^1.4.2",
"mocha": "^3.0.1",
"node-uuid": "^1.4.3",
Expand Down
5 changes: 2 additions & 3 deletions packages/bigquery/src/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ var format = require('string-format-obj');
var fs = require('fs');
var is = require('is');
var path = require('path');
var Storage = require('@google-cloud/storage');
var streamEvents = require('stream-events');
var util = require('util');

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

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

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

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

Expand Down
82 changes: 62 additions & 20 deletions packages/bigquery/test/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,17 @@ var prop = require('propprop');
var proxyquire = require('proxyquire');
var stream = require('stream');

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

function FakeFile(a, b) {
this.request = util.noop;
File.call(this, a, b);
}

var makeWritableStreamOverride;
var isCustomTypeOverride;
var fakeUtil = extend({}, util, {
isCustomType: function() {
return (isCustomTypeOverride || util.isCustomType).apply(null, arguments);
},
makeWritableStream: function() {
var args = [].slice.call(arguments);
var args = arguments;
(makeWritableStreamOverride || util.makeWritableStream).apply(null, args);
}
});
Expand Down Expand Up @@ -70,7 +68,8 @@ describe('BigQuery/Table', function() {
projectId: 'project-id',
job: function(id) {
return { id: id };
}
},
request: util.noop
}
};

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

before(function() {
Table = proxyquire('../src/table.js', {
'@google-cloud/storage': {
File: FakeFile
},
'@google-cloud/common': {
ServiceObject: FakeServiceObject,
streamRouter: fakeStreamRouter,
Expand All @@ -125,9 +121,11 @@ describe('BigQuery/Table', function() {
});

beforeEach(function() {
isCustomTypeOverride = null;
makeWritableStreamOverride = null;
tableOverrides = {};
table = new Table(DATASET, TABLE_ID);
table.bigQuery.request = util.noop;
});

describe('instantiation', function() {
Expand Down Expand Up @@ -480,12 +478,18 @@ describe('BigQuery/Table', function() {
});

describe('export', function() {
var FILE = new FakeFile({
name: 'bucket-name',
makeReq_: util.noop,
}, 'file.json');
var FILE = {
name: 'file-name.json',
bucket: {
name: 'bucket-name'
}
};

beforeEach(function() {
isCustomTypeOverride = function() {
return true;
};

table.bigQuery.job = function(id) {
return { id: id };
};
Expand Down Expand Up @@ -555,10 +559,25 @@ describe('BigQuery/Table', function() {
done();
};

table.export(FILE, done);
table.export(FILE, assert.ifError);
});

it('should check if a destination is a File', function(done) {
isCustomTypeOverride = function(dest, type) {
assert.strictEqual(dest, FILE);
assert.strictEqual(type, 'storage/file');
setImmediate(done);
return true;
};

table.export(FILE, assert.ifError);
});

it('should throw if a destination is not a File', function() {
isCustomTypeOverride = function() {
return false;
};

assert.throws(function() {
table.export({}, util.noop);
}, /Destination must be a File object/);
Expand Down Expand Up @@ -794,10 +813,18 @@ describe('BigQuery/Table', function() {

describe('import', function() {
var FILEPATH = require.resolve('./testdata/testfile.json');
var FILE = new FakeFile({
name: 'bucket-name',
makeReq_: util.noop
}, 'file.json');
var FILE = {
name: 'file-name.json',
bucket: {
name: 'bucket-name'
}
};

beforeEach(function() {
isCustomTypeOverride = function() {
return true;
};
});

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

it('should check if a destination is a File', function(done) {
isCustomTypeOverride = function(dest, type) {
assert.strictEqual(dest, FILE);
assert.strictEqual(type, 'storage/file');
setImmediate(done);
return true;
};

table.export(FILE, assert.ifError);
});

it('should throw if a File object is not provided', function() {
isCustomTypeOverride = function() {
return false;
};

assert.throws(function() {
table.import({});
}, /Source must be a File object/);
Expand Down
2 changes: 1 addition & 1 deletion packages/bigtable/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@
"bigtable"
],
"dependencies": {
"@google-cloud/common": "^0.1.0",
"arrify": "^1.0.0",
"concat-stream": "^1.5.0",
"create-error-class": "^2.0.1",
"dot-prop": "^2.4.0",
"extend": "^3.0.0",
"@google-cloud/common": "^0.1.0",
"google-proto-files": "^0.2.1",
"is": "^3.0.1",
"lodash.flatten": "^4.2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/compute/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@
"compute engine"
],
"dependencies": {
"@google-cloud/common": "^0.1.0",
"arrify": "^1.0.0",
"async": "^1.4.2",
"create-error-class": "^2.0.1",
"extend": "^3.0.0",
"gce-images": "^0.3.0",
"@google-cloud/common": "^0.1.0",
"is": "^3.0.1",
"modelo": "^4.2.0",
"string-format-obj": "^1.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/datastore/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@
"datastore"
],
"dependencies": {
"@google-cloud/common": "^0.2.0",
"arrify": "^1.0.0",
"concat-stream": "^1.5.0",
"create-error-class": "^2.0.1",
"extend": "^3.0.0",
"@google-cloud/common": "^0.2.0",
"is": "^3.0.1",
"lodash.flatten": "^4.2.0",
"modelo": "^4.2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/dns/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@
"dns"
],
"dependencies": {
"@google-cloud/common": "^0.1.0",
"arrify": "^1.0.0",
"dns-zonefile": "0.1.18",
"extend": "^3.0.0",
"@google-cloud/common": "^0.1.0",
"is": "^3.0.1",
"methmeth": "^1.0.0",
"string-format-obj": "^1.0.0"
Expand Down
4 changes: 2 additions & 2 deletions packages/google-cloud/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@
"vision"
],
"dependencies": {
"extend": "^3.0.0",
"@google-cloud/bigquery": "^0.1.1",
"@google-cloud/bigtable": "^0.1.1",
"@google-cloud/compute": "^0.1.1",
Expand All @@ -106,7 +105,8 @@
"@google-cloud/resource": "^0.1.1",
"@google-cloud/storage": "^0.1.1",
"@google-cloud/translate": "^0.1.1",
"@google-cloud/vision": "^0.1.1"
"@google-cloud/vision": "^0.1.1",
"extend": "^3.0.0"
},
"devDependencies": {
"proxyquire": "^1.7.10"
Expand Down
4 changes: 2 additions & 2 deletions packages/language/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@
"language"
],
"dependencies": {
"@google-cloud/common": "^0.1.0",
"@google-cloud/storage": "^0.1.0",
"@google-cloud/common": "^0.3.0",
"arguejs": "^0.2.3",
"arrify": "^1.0.1",
"extend": "^3.0.0",
Expand All @@ -64,6 +63,7 @@
"string-format-obj": "^1.0.0"
},
"devDependencies": {
"@google-cloud/storage": "*",
"mocha": "^2.1.0",
"node-uuid": "^1.4.7",
"proxyquire": "^1.7.10",
Expand Down
4 changes: 2 additions & 2 deletions packages/language/src/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
'use strict';

var arrify = require('arrify');
var common = require('@google-cloud/common');
var extend = require('extend');
var File = require('@google-cloud/storage').File;
var format = require('string-format-obj');
var is = require('is');
var prop = require('propprop');
Expand Down Expand Up @@ -76,7 +76,7 @@ function Document(language, config) {
this.reqOpts.document.type = 'PLAIN_TEXT';
}

if (content instanceof File) {
if (common.util.isCustomType(content, 'storage/file')) {
this.reqOpts.document.gcsContentUri = format('gs://{bucket}/{file}', {
bucket: encodeURIComponent(content.bucket.id),
file: encodeURIComponent(content.id)
Expand Down
33 changes: 26 additions & 7 deletions packages/language/test/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,16 @@ var prop = require('propprop');
var proxyquire = require('proxyquire');
var util = require('@google-cloud/common').util;

function FakeFile() {}
var isCustomTypeOverride;
var fakeUtil = extend(true, {}, util, {
isCustomType: function() {
if (isCustomTypeOverride) {
return isCustomTypeOverride.apply(null, arguments);
}

return false;
}
});

describe('Document', function() {
var DocumentCache;
Expand All @@ -36,15 +45,17 @@ describe('Document', function() {

before(function() {
Document = proxyquire('../src/document.js', {
'@google-cloud/storage': {
File: FakeFile
'@google-cloud/common': {
util: fakeUtil
}
});

DocumentCache = extend(true, {}, Document);
});

beforeEach(function() {
isCustomTypeOverride = null;

for (var property in DocumentCache) {
if (DocumentCache.hasOwnProperty(property)) {
Document[property] = DocumentCache[property];
Expand Down Expand Up @@ -123,11 +134,19 @@ describe('Document', function() {
});

it('should set the GCS content URI from a File', function() {
var file = new FakeFile();
var file = {
// Leave spaces in to check that it is URI-encoded:
id: 'file name',
bucket: {
id: 'bucket name'
}
};

// Leave spaces in to check that it is URI-encoded:
file.bucket = { id: 'bucket id' };
file.id = 'file name';
isCustomTypeOverride = function(content, type) {
assert.strictEqual(content, file);
assert.strictEqual(type, 'storage/file');
return true;
};

var document = new Document(LANGUAGE, {
content: file
Expand Down
8 changes: 4 additions & 4 deletions packages/logging/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,17 @@
"logging"
],
"dependencies": {
"@google-cloud/common": "^0.3.0",
"arrify": "^1.0.0",
"extend": "^3.0.0",
"@google-cloud/bigquery": "^0.1.0",
"@google-cloud/common": "^0.1.0",
"@google-cloud/pubsub": "^0.1.0",
"@google-cloud/storage": "^0.1.0",
"google-proto-files": "^0.2.1",
"is": "^3.0.1",
"string-format-obj": "^1.0.0"
},
"devDependencies": {
"@google-cloud/bigquery": "*",
"@google-cloud/pubsub": "*",
"@google-cloud/storage": "*",
"async": "^1.4.2",
"methmeth": "^1.0.0",
"mocha": "^3.0.1",
Expand Down
Loading

0 comments on commit 069d827

Please sign in to comment.