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 90d934b commit 38ac4c0
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 19 deletions.
6 changes: 3 additions & 3 deletions packages/google-cloud-vision/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,22 @@
"vision"
],
"dependencies": {
"@google-cloud/common": "^0.3.0",
"arrify": "^1.0.0",
"async": "^1.4.2",
"extend": "^3.0.0",
"@google-cloud/common": "^0.1.0",
"@google-cloud/storage": "^0.1.0",
"is": "^3.0.1",
"propprop": "^0.3.0",
"request": "^2.70.0",
"rgb-hex": "^1.0.0",
"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"
Expand Down
4 changes: 2 additions & 2 deletions packages/google-cloud-vision/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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}', {
Expand Down
64 changes: 61 additions & 3 deletions packages/google-cloud-vision/system-test/vision.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,68 @@
'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'),
text: path.join(__dirname, 'data/text.png'),
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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -525,4 +579,8 @@ describe('Vision', function() {
});
});
});

function generateName() {
return TESTS_PREFIX + uuid.v1();
}
});
25 changes: 14 additions & 11 deletions packages/google-cloud-vision/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 38ac4c0

Please sign in to comment.