From 24a02525fd9afd62c0dcbd3dedb2fda863ab77c9 Mon Sep 17 00:00:00 2001 From: Stephen Sawchuk Date: Thu, 25 Aug 2016 19:34:43 -0400 Subject: [PATCH 1/4] bigquery/language/logging/prediction/vision: decouple packages --- packages/bigquery/package.json | 4 +- packages/bigquery/src/table.js | 5 +- packages/bigquery/test/table.js | 82 +++++++++++++++++------ packages/language/package.json | 4 +- packages/language/src/document.js | 4 +- packages/language/test/document.js | 33 +++++++-- packages/logging/package.json | 8 +-- packages/logging/src/index.js | 15 ++--- packages/logging/src/sink.js | 4 +- packages/logging/test/index.js | 104 +++++++++++++++-------------- packages/prediction/package.json | 2 +- packages/vision/package.json | 3 +- packages/vision/src/index.js | 4 +- packages/vision/test/index.js | 25 ++++--- 14 files changed, 182 insertions(+), 115 deletions(-) diff --git a/packages/bigquery/package.json b/packages/bigquery/package.json index f52795c9c14..c68248d47e0 100644 --- a/packages/bigquery/package.json +++ b/packages/bigquery/package.json @@ -53,8 +53,7 @@ "arrify": "^1.0.0", "duplexify": "^3.2.0", "extend": "^3.0.0", - "@google-cloud/common": "^0.1.0", - "@google-cloud/storage": "^0.1.0", + "@google-cloud/common": "^0.3.0", "is": "^3.0.1", "modelo": "^4.2.0", "stream-events": "^1.0.1", @@ -62,6 +61,7 @@ }, "devDependencies": { "async": "^1.4.2", + "@google-cloud/storage": "*", "mocha": "^3.0.1", "node-uuid": "^1.4.3", "propprop": "^0.3.0", diff --git a/packages/bigquery/src/table.js b/packages/bigquery/src/table.js index 5aa75928fc4..a608652ce24 100644 --- a/packages/bigquery/src/table.js +++ b/packages/bigquery/src/table.js @@ -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'); @@ -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.'); } @@ -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.'); } diff --git a/packages/bigquery/test/table.js b/packages/bigquery/test/table.js index 3cc64960f75..20de94c774c 100644 --- a/packages/bigquery/test/table.js +++ b/packages/bigquery/test/table.js @@ -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); } }); @@ -70,7 +68,8 @@ describe('BigQuery/Table', function() { projectId: 'project-id', job: function(id) { return { id: id }; - } + }, + request: util.noop } }; @@ -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, @@ -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() { @@ -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 }; }; @@ -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/); @@ -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' }; @@ -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/); diff --git a/packages/language/package.json b/packages/language/package.json index aa78ba4beb7..70fb358b95f 100644 --- a/packages/language/package.json +++ b/packages/language/package.json @@ -52,11 +52,10 @@ "language" ], "dependencies": { - "@google-cloud/common": "^0.1.0", - "@google-cloud/storage": "^0.1.0", "arguejs": "^0.2.3", "arrify": "^1.0.1", "extend": "^3.0.0", + "@google-cloud/common": "^0.3.0", "google-gax": "^0.6.0", "google-proto-files": "^0.4.0", "is": "^3.0.1", @@ -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", diff --git a/packages/language/src/document.js b/packages/language/src/document.js index 762e7625b44..ca3e685636c 100644 --- a/packages/language/src/document.js +++ b/packages/language/src/document.js @@ -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'); @@ -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) diff --git a/packages/language/test/document.js b/packages/language/test/document.js index 2801930c4f8..c6d69cc16ce 100644 --- a/packages/language/test/document.js +++ b/packages/language/test/document.js @@ -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; @@ -36,8 +45,8 @@ describe('Document', function() { before(function() { Document = proxyquire('../src/document.js', { - '@google-cloud/storage': { - File: FakeFile + '@google-cloud/common': { + util: fakeUtil } }); @@ -45,6 +54,8 @@ describe('Document', function() { }); beforeEach(function() { + isCustomTypeOverride = null; + for (var property in DocumentCache) { if (DocumentCache.hasOwnProperty(property)) { Document[property] = DocumentCache[property]; @@ -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 diff --git a/packages/logging/package.json b/packages/logging/package.json index 61bb205e7d1..941836311af 100644 --- a/packages/logging/package.json +++ b/packages/logging/package.json @@ -52,16 +52,16 @@ "dependencies": { "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": { "async": "^1.4.2", + "@google-cloud/bigquery": "*", + "@google-cloud/common": "*", + "@google-cloud/pubsub": "*", + "@google-cloud/storage": "*", "methmeth": "^1.0.0", "mocha": "^3.0.1", "node-uuid": "^1.4.3", diff --git a/packages/logging/src/index.js b/packages/logging/src/index.js index bc83a4e8460..cd5843ca1c3 100644 --- a/packages/logging/src/index.js +++ b/packages/logging/src/index.js @@ -21,14 +21,11 @@ 'use strict'; var arrify = require('arrify'); -var BigQuery = require('@google-cloud/bigquery'); var common = require('@google-cloud/common'); var extend = require('extend'); var format = require('string-format-obj'); var googleProtoFiles = require('google-proto-files'); var is = require('is'); -var PubSub = require('@google-cloud/pubsub'); -var Storage = require('@google-cloud/storage'); var util = require('util'); /** @@ -152,18 +149,18 @@ Logging.prototype.createSink = function(name, config, callback) { throw new Error('A sink configuration object must be provided.'); } - if (config.destination instanceof Storage.Bucket) { - this.setAclForBucket_(name, config, callback); + if (common.util.isCustomType(config.destination, 'bigquery/dataset')) { + this.setAclForDataset_(name, config, callback); return; } - if (config.destination instanceof BigQuery.Dataset) { - this.setAclForDataset_(name, config, callback); + if (common.util.isCustomType(config.destination, 'pubsub/topic')) { + this.setAclForTopic_(name, config, callback); return; } - if (config.destination instanceof PubSub.Topic) { - this.setAclForTopic_(name, config, callback); + if (common.util.isCustomType(config.destination, 'storage/bucket')) { + this.setAclForBucket_(name, config, callback); return; } diff --git a/packages/logging/src/sink.js b/packages/logging/src/sink.js index ef7c866183a..0f547cbe9ce 100644 --- a/packages/logging/src/sink.js +++ b/packages/logging/src/sink.js @@ -57,7 +57,9 @@ function Sink(logging, name) { * * @example * var config = { - * // ... + * destination: { + * // ... + * } * }; * * sink.create(config, function(err, sink, apiResponse) { diff --git a/packages/logging/test/index.js b/packages/logging/test/index.js index c161064c693..215a88c3ab0 100644 --- a/packages/logging/test/index.js +++ b/packages/logging/test/index.js @@ -41,21 +41,16 @@ var fakeStreamRouter = { } }; +var isCustomTypeOverride; var fakeUtil = extend({}, util, { - makeAuthenticatedRequestFactory: util.noop -}); - -function FakeBucket() { - this.calledWith_ = arguments; -} - -function FakeDataset() { - this.calledWith_ = arguments; -} + isCustomType: function() { + if (isCustomTypeOverride) { + return isCustomTypeOverride.apply(null, arguments); + } -function FakeTopic() { - this.calledWith_ = arguments; -} + return false; + } +}); function FakeEntry() { this.calledWith_ = arguments; @@ -90,15 +85,6 @@ describe('Logging', function() { streamRouter: fakeStreamRouter, util: fakeUtil }, - '@google-cloud/bigquery': { - Dataset: FakeDataset - }, - '@google-cloud/pubsub': { - Topic: FakeTopic - }, - '@google-cloud/storage': { - Bucket: FakeBucket - }, './log.js': FakeLog, './entry.js': FakeEntry, './sink.js': FakeSink @@ -106,11 +92,12 @@ describe('Logging', function() { }); beforeEach(function() { + isCustomTypeOverride = null; + logging = new Logging({ projectId: PROJECT_ID }); logging.projectId = PROJECT_ID; - logging.request = util.noop; }); @@ -179,14 +166,19 @@ describe('Logging', function() { }, /A sink configuration object must be provided\./); }); - it('should set acls for a Bucket destination', function(done) { - var bucket = new FakeBucket(); + it('should set acls for a Dataset destination', function(done) { + var dataset = {}; var CONFIG = { - destination: bucket + destination: dataset }; - logging.setAclForBucket_ = function(name, config, callback) { + isCustomTypeOverride = function(destination, type) { + assert.strictEqual(destination, dataset); + return type === 'bigquery/dataset'; + }; + + logging.setAclForDataset_ = function(name, config, callback) { assert.strictEqual(name, SINK_NAME); assert.strictEqual(config, CONFIG); callback(); // done() @@ -195,14 +187,19 @@ describe('Logging', function() { logging.createSink(SINK_NAME, CONFIG, done); }); - it('should set acls for a Dataset destination', function(done) { - var dataset = new FakeDataset(); + it('should set acls for a Topic destination', function(done) { + var topic = {}; var CONFIG = { - destination: dataset + destination: topic }; - logging.setAclForDataset_ = function(name, config, callback) { + isCustomTypeOverride = function(destination, type) { + assert.strictEqual(destination, topic); + return type === 'pubsub/topic'; + }; + + logging.setAclForTopic_ = function(name, config, callback) { assert.strictEqual(name, SINK_NAME); assert.strictEqual(config, CONFIG); callback(); // done() @@ -211,14 +208,19 @@ describe('Logging', function() { logging.createSink(SINK_NAME, CONFIG, done); }); - it('should set acls for a Topic destination', function(done) { - var topic = new FakeTopic(); + it('should set acls for a Bucket destination', function(done) { + var bucket = {}; var CONFIG = { - destination: topic + destination: bucket }; - logging.setAclForTopic_ = function(name, config, callback) { + isCustomTypeOverride = function(destination, type) { + assert.strictEqual(destination, bucket); + return type === 'storage/bucket'; + }; + + logging.setAclForBucket_ = function(name, config, callback) { assert.strictEqual(name, SINK_NAME); assert.strictEqual(config, CONFIG); callback(); // done() @@ -227,6 +229,7 @@ describe('Logging', function() { logging.createSink(SINK_NAME, CONFIG, done); }); + describe('API request', function() { it('should make the correct API request', function(done) { var config = { @@ -574,11 +577,12 @@ describe('Logging', function() { var bucket; beforeEach(function() { - bucket = new FakeBucket(); - bucket.name = 'bucket-name'; - bucket.acl = { - owners: { - addGroup: util.noop + bucket = { + name: 'bucket-name', + acl: { + owners: { + addGroup: util.noop + } } }; @@ -653,10 +657,11 @@ describe('Logging', function() { var dataset; beforeEach(function() { - dataset = new FakeDataset(); - dataset.id = 'dataset-id'; - dataset.parent = { - projectId: PROJECT_ID + dataset = { + id: 'dataset-id', + parent: { + projectId: PROJECT_ID + } }; CONFIG = { @@ -773,11 +778,12 @@ describe('Logging', function() { var topic; beforeEach(function() { - topic = new FakeTopic(); - topic.name = 'topic-name'; - topic.iam = { - getPolicy: util.noop, - setPolicy: util.noop + topic = { + name: 'topic-name', + iam: { + getPolicy: util.noop, + setPolicy: util.noop + } }; CONFIG = { diff --git a/packages/prediction/package.json b/packages/prediction/package.json index c3837bbf132..a40420c16ed 100644 --- a/packages/prediction/package.json +++ b/packages/prediction/package.json @@ -63,7 +63,7 @@ "devDependencies": { "async": "^1.4.2", "concat-stream": "^1.5.0", - "@google-cloud/storage": "^0.1.0", + "@google-cloud/storage": "*", "mocha": "^3.0.1", "node-uuid": "^1.4.3", "proxyquire": "^1.7.10" diff --git a/packages/vision/package.json b/packages/vision/package.json index a1204ba4c0b..7c12b38662b 100644 --- a/packages/vision/package.json +++ b/packages/vision/package.json @@ -53,8 +53,7 @@ "arrify": "^1.0.0", "async": "^1.4.2", "extend": "^3.0.0", - "@google-cloud/common": "^0.1.0", - "@google-cloud/storage": "^0.1.0", + "@google-cloud/common": "^0.3.0", "is": "^3.0.1", "propprop": "^0.3.0", "request": "^2.70.0", diff --git a/packages/vision/src/index.js b/packages/vision/src/index.js index 9c706e4c148..50f3dc0df28 100644 --- a/packages/vision/src/index.js +++ b/packages/vision/src/index.js @@ -30,7 +30,6 @@ var is = require('is'); var prop = require('propprop'); var request = require('request'); var rgbHex = require('rgb-hex'); -var Storage = require('@google-cloud/storage'); var util = require('util'); var PKG = require('../package.json'); @@ -1275,7 +1274,8 @@ Vision.findImages_ = function(images, callback) { }); return; } - if (image instanceof Storage.File) { + + if (common.util.isCustomType(image, 'storage/file')) { callback(null, { source: { gcsImageUri: format('gs://{bucketName}/{fileName}', { diff --git a/packages/vision/test/index.js b/packages/vision/test/index.js index 777b8510282..5862407e5d6 100644 --- a/packages/vision/test/index.js +++ b/packages/vision/test/index.js @@ -40,10 +40,6 @@ function FakeService() { nodeutil.inherits(FakeService, Service); -function FakeFile() { - this.calledWith_ = arguments; -} - var requestOverride = null; var fakeRequest = function() { return (requestOverride || util.noop).apply(this, arguments); @@ -59,9 +55,6 @@ describe('Vision', function() { before(function() { Vision = proxyquire('../', { request: fakeRequest, - '@google-cloud/storage': { - File: FakeFile - }, '@google-cloud/common': { Service: FakeService, util: fakeUtil @@ -860,11 +853,21 @@ describe('Vision', function() { describe('findImages_', function() { it('should convert a File object', function(done) { - var file = new FakeFile(); - file.bucket = { - name: 'bucket-name' + var file = { + name: 'file-name', + bucket: { + name: 'bucket-name' + } + }; + + var isCustomType = util.isCustomType; + + fakeUtil.isCustomType = function(unknown, type) { + fakeUtil.isCustomType = isCustomType; + assert.strictEqual(unknown, file); + assert.strictEqual(type, 'storage/file'); + return true; }; - file.name = 'file-name'; Vision.findImages_(file, function(err, images) { assert.ifError(err); From 3bfe656c922de78fe28e2e579b62594288af74fa Mon Sep 17 00:00:00 2001 From: Stephen Sawchuk Date: Fri, 26 Aug 2016 14:58:18 -0400 Subject: [PATCH 2/4] tests: allow more time for docs tests to run --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d23487b3cf6..b985ee18ae4 100644 --- a/package.json +++ b/package.json @@ -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" From 3bb45aba8c874ecc6ee1fb3fcac8d398b6108604 Mon Sep 17 00:00:00 2001 From: Stephen Sawchuk Date: Fri, 26 Aug 2016 16:53:31 -0400 Subject: [PATCH 3/4] add vision test --- packages/vision/package.json | 5 ++- packages/vision/system-test/vision.js | 64 +++++++++++++++++++++++++-- 2 files changed, 64 insertions(+), 5 deletions(-) diff --git a/packages/vision/package.json b/packages/vision/package.json index 7c12b38662b..d7c28afa894 100644 --- a/packages/vision/package.json +++ b/packages/vision/package.json @@ -50,10 +50,10 @@ "vision" ], "dependencies": { + "@google-cloud/common": "^0.3.0", "arrify": "^1.0.0", "async": "^1.4.2", "extend": "^3.0.0", - "@google-cloud/common": "^0.3.0", "is": "^3.0.1", "propprop": "^0.3.0", "request": "^2.70.0", @@ -61,10 +61,11 @@ "string-format-obj": "^1.0.0" }, "devDependencies": { - "async": "^1.4.2", + "@google-cloud/storage": "*", "deep-strict-equal": "^0.1.0", "mocha": "^3.0.1", "multiline": "^1.0.2", + "node-uuid": "^1.4.7", "normalize-newline": "^2.0.0", "proxyquire": "^1.7.10", "tmp": "0.0.27" diff --git a/packages/vision/system-test/vision.js b/packages/vision/system-test/vision.js index 16ab6b7f8ce..72bddce4a4a 100644 --- a/packages/vision/system-test/vision.js +++ b/packages/vision/system-test/vision.js @@ -17,18 +17,20 @@ 'use strict'; var assert = require('assert'); +var async = require('async'); var fs = require('fs'); var http = require('http'); var is = require('is'); var multiline = require('multiline'); var normalizeNewline = require('normalize-newline'); var path = require('path'); +var Storage = require('@google-cloud/storage'); +var uuid = require('node-uuid'); var env = require('../../../system-test/env.js'); var Vision = require('../'); describe('Vision', function() { - var vision; var IMAGES = { logo: path.join(__dirname, 'data/logo.jpg'), rushmore: path.join(__dirname, 'data/rushmore.jpg'), @@ -36,8 +38,47 @@ describe('Vision', function() { malformed: path.join(__dirname, 'data/index.yaml') }; - beforeEach(function() { - vision = new Vision(env); + var TESTS_PREFIX = 'gcloud-vision-test'; + + var storage = new Storage(env); + var vision = new Vision(env); + + var bucket = storage.bucket(generateName()); + var file = bucket.file('logo.jpg'); + + before(function(done) { + bucket.create(function(err) { + if (err) { + done(err); + return; + } + + bucket.upload(IMAGES.logo, done); + }); + }); + + after(function(done) { + storage.getBuckets({ + prefix: TESTS_PREFIX + }, function(err, buckets) { + if (err) { + done(err); + return; + } + + function deleteBucket(bucket, callback) { + bucket.deleteFiles(function(err) { + if (err) { + callback(err); + return; + } + + bucket.delete(callback); + }); + } + + async.each(buckets, deleteBucket, done); + }); }); it('should detect from a URL', function(done) { @@ -66,6 +107,19 @@ describe('Vision', function() { }); }); + it('should detect from a File', function(done) { + vision.detect(file, ['logos'], function(err, logos) { + assert.ifError(err); + + var expected = ['Google']; + expected.errors = []; + + assert.deepEqual(logos, expected); + + done(); + }); + }); + it('should detect from a Buffer', function(done) { var buffer = fs.readFileSync(IMAGES.logo); vision.detect(buffer, ['logos'], function(err, logos) { @@ -525,4 +579,8 @@ describe('Vision', function() { }); }); }); + + function generateName() { + return TESTS_PREFIX + uuid.v1(); + } }); From 2f87aef2b2a8b0bf6f11a35da738c501cbcde85c Mon Sep 17 00:00:00 2001 From: Stephen Sawchuk Date: Fri, 26 Aug 2016 16:53:38 -0400 Subject: [PATCH 4/4] resort dependencies like npm does --- packages/bigquery/package.json | 4 ++-- packages/bigtable/package.json | 2 +- packages/compute/package.json | 2 +- packages/datastore/package.json | 2 +- packages/dns/package.json | 2 +- packages/google-cloud/package.json | 4 ++-- packages/language/package.json | 2 +- packages/logging/package.json | 4 ++-- packages/prediction/package.json | 4 ++-- packages/pubsub/package.json | 2 +- packages/resource/package.json | 2 +- packages/storage/package.json | 2 +- packages/translate/package.json | 2 +- 13 files changed, 17 insertions(+), 17 deletions(-) diff --git a/packages/bigquery/package.json b/packages/bigquery/package.json index c68248d47e0..bb887c79c2b 100644 --- a/packages/bigquery/package.json +++ b/packages/bigquery/package.json @@ -50,18 +50,18 @@ "bigquery" ], "dependencies": { + "@google-cloud/common": "^0.3.0", "arrify": "^1.0.0", "duplexify": "^3.2.0", "extend": "^3.0.0", - "@google-cloud/common": "^0.3.0", "is": "^3.0.1", "modelo": "^4.2.0", "stream-events": "^1.0.1", "string-format-obj": "^1.0.0" }, "devDependencies": { - "async": "^1.4.2", "@google-cloud/storage": "*", + "async": "^1.4.2", "mocha": "^3.0.1", "node-uuid": "^1.4.3", "propprop": "^0.3.0", diff --git a/packages/bigtable/package.json b/packages/bigtable/package.json index 9cc8dc976e4..e1d9ded8aa6 100644 --- a/packages/bigtable/package.json +++ b/packages/bigtable/package.json @@ -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", diff --git a/packages/compute/package.json b/packages/compute/package.json index 12bbfd30464..77ca0ee8ab9 100644 --- a/packages/compute/package.json +++ b/packages/compute/package.json @@ -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" diff --git a/packages/datastore/package.json b/packages/datastore/package.json index 90f2adeae5c..a821c708241 100644 --- a/packages/datastore/package.json +++ b/packages/datastore/package.json @@ -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", diff --git a/packages/dns/package.json b/packages/dns/package.json index 28a41878e01..0f95be64d53 100644 --- a/packages/dns/package.json +++ b/packages/dns/package.json @@ -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" diff --git a/packages/google-cloud/package.json b/packages/google-cloud/package.json index 327a1f85eb8..b17b7e81895 100644 --- a/packages/google-cloud/package.json +++ b/packages/google-cloud/package.json @@ -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", @@ -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" diff --git a/packages/language/package.json b/packages/language/package.json index 70fb358b95f..910f2d264dc 100644 --- a/packages/language/package.json +++ b/packages/language/package.json @@ -52,10 +52,10 @@ "language" ], "dependencies": { + "@google-cloud/common": "^0.3.0", "arguejs": "^0.2.3", "arrify": "^1.0.1", "extend": "^3.0.0", - "@google-cloud/common": "^0.3.0", "google-gax": "^0.6.0", "google-proto-files": "^0.4.0", "is": "^3.0.1", diff --git a/packages/logging/package.json b/packages/logging/package.json index 941836311af..55a2cf8395c 100644 --- a/packages/logging/package.json +++ b/packages/logging/package.json @@ -50,6 +50,7 @@ "logging" ], "dependencies": { + "@google-cloud/common": "^0.3.0", "arrify": "^1.0.0", "extend": "^3.0.0", "google-proto-files": "^0.2.1", @@ -57,11 +58,10 @@ "string-format-obj": "^1.0.0" }, "devDependencies": { - "async": "^1.4.2", "@google-cloud/bigquery": "*", - "@google-cloud/common": "*", "@google-cloud/pubsub": "*", "@google-cloud/storage": "*", + "async": "^1.4.2", "methmeth": "^1.0.0", "mocha": "^3.0.1", "node-uuid": "^1.4.3", diff --git a/packages/prediction/package.json b/packages/prediction/package.json index a40420c16ed..685890d3939 100644 --- a/packages/prediction/package.json +++ b/packages/prediction/package.json @@ -50,10 +50,10 @@ "prediction" ], "dependencies": { + "@google-cloud/common": "^0.1.0", "JSONStream": "^1.0.7", "arrify": "^1.0.0", "extend": "^3.0.0", - "@google-cloud/common": "^0.1.0", "is": "^3.0.1", "pumpify": "^1.3.3", "stream-events": "^1.0.1", @@ -61,9 +61,9 @@ "through2": "^2.0.0" }, "devDependencies": { + "@google-cloud/storage": "*", "async": "^1.4.2", "concat-stream": "^1.5.0", - "@google-cloud/storage": "*", "mocha": "^3.0.1", "node-uuid": "^1.4.3", "proxyquire": "^1.7.10" diff --git a/packages/pubsub/package.json b/packages/pubsub/package.json index a24efc5aed8..45063745e46 100644 --- a/packages/pubsub/package.json +++ b/packages/pubsub/package.json @@ -50,9 +50,9 @@ "pubsub" ], "dependencies": { + "@google-cloud/common": "^0.1.0", "arrify": "^1.0.0", "extend": "^3.0.0", - "@google-cloud/common": "^0.1.0", "is": "^3.0.1", "modelo": "^4.2.0", "propprop": "^0.3.0" diff --git a/packages/resource/package.json b/packages/resource/package.json index d34fa6fc76a..37d969c7e4e 100644 --- a/packages/resource/package.json +++ b/packages/resource/package.json @@ -50,8 +50,8 @@ "resource" ], "dependencies": { - "extend": "^3.0.0", "@google-cloud/common": "^0.1.0", + "extend": "^3.0.0", "is": "^3.0.1" }, "devDependencies": { diff --git a/packages/storage/package.json b/packages/storage/package.json index e86a20c3898..fae6ce61107 100644 --- a/packages/storage/package.json +++ b/packages/storage/package.json @@ -50,6 +50,7 @@ "storage" ], "dependencies": { + "@google-cloud/common": "^0.1.0", "arrify": "^1.0.0", "async": "^1.4.2", "concat-stream": "^1.5.0", @@ -57,7 +58,6 @@ "duplexify": "^3.2.0", "extend": "^3.0.0", "gcs-resumable-upload": "^0.7.1", - "@google-cloud/common": "^0.1.0", "hash-stream-validation": "^0.2.1", "is": "^3.0.1", "mime-types": "^2.0.8", diff --git a/packages/translate/package.json b/packages/translate/package.json index f5c25beca9e..34941792c3b 100644 --- a/packages/translate/package.json +++ b/packages/translate/package.json @@ -50,9 +50,9 @@ "translate" ], "dependencies": { + "@google-cloud/common": "^0.1.0", "arrify": "^1.0.0", "extend": "^3.0.0", - "@google-cloud/common": "^0.1.0", "is": "^3.0.1", "propprop": "^0.3.0" },