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 sofisl committed Oct 13, 2022
1 parent 67bab24 commit 6597ab6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
4 changes: 2 additions & 2 deletions packages/google-cloud-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/google-cloud-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/google-cloud-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

0 comments on commit 6597ab6

Please sign in to comment.