Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jul 20, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
ab03d7c
mv samples/productSearch/system-test/* samples/system-test/
Nov 13, 2018
58fb6e2
failing test fixes
nirupa-kumar Nov 14, 2018
546fee9
failing test fixes
nirupa-kumar Nov 14, 2018
600b8f2
failing test fixes
nirupa-kumar Nov 14, 2018
c74671a
failing test fixes
nirupa-kumar Nov 14, 2018
01756a6
failing test fixes
nirupa-kumar Nov 14, 2018
0037647
testing possible solutions for fix
nirupa-kumar Nov 14, 2018
3914b5f
testing possible solutions for fix
nirupa-kumar Nov 14, 2018
dfc4b96
testing possible solutions for fix
nirupa-kumar Nov 14, 2018
49c8fbf
testing possible solutions for fix
nirupa-kumar Nov 15, 2018
d8a7fb6
testing possible solutions for fix
nirupa-kumar Nov 15, 2018
80d0320
testing possible solutions for fix
nirupa-kumar Nov 15, 2018
b71c6ea
testing possible solutions for fix
nirupa-kumar Nov 15, 2018
19d5566
Merge branch 'master' of https://github.com/googleapis/nodejs-vision …
nirupa-kumar Nov 16, 2018
4f33f59
testing possible solutions for fix
nirupa-kumar Nov 16, 2018
d33a41f
testing possible solutions for fix
nirupa-kumar Nov 16, 2018
cc0ee1b
testing possible solutions for fix
nirupa-kumar Nov 16, 2018
7882a60
testing possible solutions for fix
nirupa-kumar Nov 16, 2018
4aa9124
testing possible solutions for fix
nirupa-kumar Nov 18, 2018
a6692f4
testing possible solutions for fix
nirupa-kumar Nov 18, 2018
bbfa2c6
testing possible solutions for fix
nirupa-kumar Nov 18, 2018
972b6d0
testing possible solutions for fix
nirupa-kumar Nov 18, 2018
1e37d96
Merge branch 'master' of https://github.com/googleapis/nodejs-vision …
nirupa-kumar Nov 19, 2018
06dc431
testing possible fixes
nirupa-kumar Nov 19, 2018
949e940
testing possible solutions for fix
nirupa-kumar Nov 19, 2018
c7db6cf
testing possible solutions for fix
nirupa-kumar Nov 19, 2018
2f95a1f
testing possible solutions for fix
nirupa-kumar Nov 19, 2018
9ed5cf2
testing possible solutions for fix
nirupa-kumar Nov 21, 2018
2a8075b
checking if import works within a reasonable timeframe now.
nirupa-kumar Nov 26, 2018
fb6084d
testing possible solutions for fix
nirupa-kumar Nov 26, 2018
b573c25
Merge branch 'master' into make-product-search-tests-run
JustinBeckwith Nov 27, 2018
88ddb9d
Merge branch 'master' of https://github.com/googleapis/nodejs-vision …
nirupa-kumar Nov 27, 2018
a9a1d44
testing possible solutions for fix
nirupa-kumar Nov 27, 2018
66a31b7
Merge remote-tracking branch 'origin/make-product-search-tests-run' i…
nirupa-kumar Nov 27, 2018
33b92e5
testing possible solutions for fix
nirupa-kumar Nov 27, 2018
b9fa538
testing possible solutions for fix
nirupa-kumar Nov 27, 2018
925bd50
testing possible solutions for fix
nirupa-kumar Nov 27, 2018
b27fae9
testing possible solutions for fix
nirupa-kumar Nov 27, 2018
27c8201
testing possible fix for the face detection test failure
nirupa-kumar Nov 27, 2018
eec2183
fixing review comments
nirupa-kumar Nov 27, 2018
a438cee
fixing face Detection code
nirupa-kumar Nov 28, 2018
bf34885
fixing face Detection code
nirupa-kumar Nov 28, 2018
0002d3e
fixing face Detection code
nirupa-kumar Nov 28, 2018
87679cd
fixing face Detection code
nirupa-kumar Nov 28, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion samples/faceDetection.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function highlightFaces(inputFile, faces, outputFile, Canvas, callback) {
// Open the original image into a canvas
const img = new Image();
img.src = image;
const canvas = new Canvas(img.width, img.height);
const canvas = new Canvas.Canvas(img.width, img.height);
const context = canvas.getContext('2d');
context.drawImage(img, 0, 0, img.width, img.height);

Expand Down
7 changes: 3 additions & 4 deletions samples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@
"mathjs": "^5.0.4",
"natural": "^0.6.1",
"redis": "^2.8.0",
"yargs": "^12.0.0"
"yargs": "^12.0.0",
"canvas": "^2.0.0"
},
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "^3.0.0",
"@google-cloud/storage": "^2.0.0",
"mocha": "^5.0.0",
"uuid": "^3.2.1"
},
"optionalDependencies": {
"canvas": "^2.0.0"
}
"optionalDependencies": {}
}
2 changes: 1 addition & 1 deletion samples/productSearch/products.v1p3beta1.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ async function listProducts(projectId, location) {
// Resource path that represents Google Cloud Platform location.
const locationPath = client.locationPath(projectId, location);

const [products] = client.listProducts({parent: locationPath});
const [products] = await client.listProducts({parent: locationPath});
products.forEach(product => {
console.log(`Product name: ${product.name}`);
console.log(`Product id: ${product.name.split('/').pop()}`);
Expand Down
2 changes: 1 addition & 1 deletion samples/productSearch/similarProducts.v1p3beta1.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async function getSimilarProductsFile(
/**
* TODO(developer): Uncomment the following line before running the sample.
*/
// const projectId = 'java-docs-samples-testing';
// const projectId = 'nodejs-docs-samples';
// const location = 'us-west1';
// const productSetId = 'indexed_product_set_id_for_testing';
// const productCategory = 'apparel';
Expand Down
Binary file added samples/resources/shoes_1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
67 changes: 14 additions & 53 deletions samples/system-test/faceDetection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,43 +15,13 @@

'use strict';

const fs = require(`fs`);
const path = require(`path`);
const path = require('path');
const assert = require('assert');
const tools = require(`@google-cloud/nodejs-repo-tools`);

class MockCanvas {
getContext() {
return {
drawImage: () => {},
beginPath: () => {},
lineTo: () => {},
stroke: () => {},
};
}

pngStream() {
return {
on: (event, cb) => {
if (event === 'end') {
setTimeout(cb, 1000);
} else if (event === `data`) {
/* eslint-disable */
cb(`test`);
cb(`foo`);
cb(`bar`);
/* eslint-enable */
}
},
};
}
}

MockCanvas.Image = class Image {};

const faceDetectionExample = require(`../faceDetection`);
const inputFile = path.join(__dirname, `../resources`, `face.png`);
const outputFile = path.join(__dirname, `../../vision`, `out.png`);
Comment thread
nirupa-kumar marked this conversation as resolved.
const tools = require('@google-cloud/nodejs-repo-tools');
const cmd = `node faceDetection.js`;
const cwd = path.join(__dirname, `..`);
const inputFile = path.join(__dirname, '../resources', 'face.png');
const outputFile = path.join(__dirname, '../../', 'out.png');

describe(`face detection`, () => {
before(tools.checkCredentials);
Expand All @@ -66,23 +36,14 @@ describe(`face detection`, () => {
console.warn('Face detection timed out!');
}
}, 60);

faceDetectionExample.main(
inputFile,
outputFile,
MockCanvas,
(err, faces) => {
assert.ifError(err);
assert.strictEqual(faces.length, 1);

const image = fs.readFileSync(outputFile);
assert.strictEqual(image.toString(`utf8`), `testfoobar`);
assert.ok(console.log.calledWith(`Found 1 face`));
assert.ok(console.log.calledWith(`Highlighting...`));
assert.ok(console.log.calledWith(`Finished!`));
done = true;
clearTimeout(timeout);
}
const output = await tools.runAsync(
`${cmd} ${inputFile} ${outputFile}`,
cwd
);
assert.ok(output.includes('Found 1 face'));
assert.ok(output.includes('Highlighting...'));
assert.ok(output.includes('Finished!'));
done = true;
clearTimeout(timeout);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const path = require(`path`);
const assert = require('assert');
const tools = require(`@google-cloud/nodejs-repo-tools`);
const cmd = `node importProductSets.v1p3beta1.js`;
const cwd = path.join(__dirname, `..`);
const cwd = path.join(__dirname, `..`, `productSearch`);

//Shared fixture data for product tests
const testImportProductSets = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,22 @@
'use strict';

const path = require(`path`);
const uuid = require(`uuid`);
const vision = require('@google-cloud/vision').v1p3beta1;
const productSearchClient = new vision.ProductSearchClient();
const assert = require('assert');
const tools = require(`@google-cloud/nodejs-repo-tools`);
const cmd = `node productSearch.v1p3beta1.js`;
const cwd = path.join(__dirname, `..`);
const cwd = path.join(__dirname, `..`, `productSearch`);

// Shared fixture data for product tests
const testProductSet = {
projectId: process.env.GCLOUD_PROJECT,
location: 'us-west1',
productCategory: 'homegoods',
productId: 'test_product_id_1',
productSetId: 'test_product_set_id_1',
productId: `test_product_id${uuid.v4()}`,
Comment thread
nirupa-kumar marked this conversation as resolved.
productDisplayName: 'test_product_display_name_1',
productSetId: `test_product_set_id${uuid.v4()}`,
productSetDisplayName: 'test_product_set_display_name_1',
};

Expand All @@ -47,43 +49,43 @@ describe(`product search`, () => {

before(async () => {
// Create a test product set for each test
try {
await productSearchClient.createProduct({
parent: productSearchClient.locationPath(
testProductSet.projectId,
testProductSet.location
),
productId: testProductSet.productId,
product: {
displayName: testProductSet.productDisplayName,
productCategory: testProductSet.productCategory,
},
});
testProductSet.createdProductPaths.push(testProductSet.productPath);
} catch (err) {} // ignore error
await productSearchClient.createProduct({
parent: productSearchClient.locationPath(
testProductSet.projectId,
testProductSet.location
),
productId: testProductSet.productId,
product: {
displayName: testProductSet.productDisplayName,
productCategory: testProductSet.productCategory,
},
});
testProductSet.createdProductPaths.push(testProductSet.productPath);

try {
await productSearchClient.createProductSet({
parent: productSearchClient.locationPath(
testProductSet.projectId,
testProductSet.location
),
productSetId: testProductSet.productSetId,
productSet: {
displayName: testProductSet.productSetDisplayName,
},
});
testProductSet.createdProductSetPaths.push(
testProductSet.createdProductSetPaths
);
} catch (err) {} // ignore error
await productSearchClient.createProductSet({
parent: productSearchClient.locationPath(
testProductSet.projectId,
testProductSet.location
),
productSetId: testProductSet.productSetId,
productSet: {
displayName: testProductSet.productSetDisplayName,
},
});
testProductSet.createdProductSetPaths.push(
testProductSet.createdProductSetPaths
);
});

after(async () => {
// Delete products sets after each test
testProductSet.createdProductSetPaths.forEach(async path => {
try {
await productSearchClient.deleteProductSet({name: path});
} catch (err) {} // ignore error
});
testProductSet.createdProductPaths.forEach(async path => {
try {
await productSearchClient.deleteProduct({name: path});
} catch (err) {} // ignore error
});
Expand All @@ -100,18 +102,14 @@ describe(`product search`, () => {
assert.ok(output.includes(`Product added to product set.`));
});

test(`remove a product from a product set`, async () => {
it(`should remove a product from a product set`, async () => {
const output = await tools.runAsync(
`${cmd} removeProductFromProductSet "${testProductSet.projectId}" "${
testProductSet.location
}" "${testProductSet.productId}" "${testProductSet.productSetId}"`,
cwd
);

console.log('---------------');
console.log(output);
console.log('---------------');

assert.ok(output.includes(`Product removed from product set.`));
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ const productSearch = new vision.ProductSearchClient();
const assert = require('assert');
const tools = require(`@google-cloud/nodejs-repo-tools`);
const cmd = `node productSets.v1p3beta1.js`;
const cwd = path.join(__dirname, `..`);
const cwd = path.join(__dirname, `..`, `productSearch`);

// Shared fixture data for product tests
const testProductSet = {
projectId: process.env.GCLOUD_PROJECT,
location: 'us-west1',
productSetId: 'test_product_set_id_1',
productSetId: `test_product_set_id${uuid.v4()}`,
productSetDisplayName: 'test_product_set_display_name_1',
};
testProductSet.productSetPath = productSearch.productSetPath(
Expand Down Expand Up @@ -57,21 +57,19 @@ describe(`product sets`, () => {

before(async () => {
// Create a test product set for each test
try {
await productSearch.createProductSet({
parent: productSearch.locationPath(
testProductSet.projectId,
testProductSet.location
),
productSetId: testProductSet.productSetId,
productSet: {
displayName: testProductSet.productSetDisplayName,
},
});
testProductSet.createdProductSetPaths.push(
testProductSet.createdProductSetPaths
);
} catch (err) {} // ignore error
await productSearch.createProductSet({
parent: productSearch.locationPath(
testProductSet.projectId,
testProductSet.location
),
productSetId: testProductSet.productSetId,
productSet: {
displayName: testProductSet.productSetDisplayName,
},
});
testProductSet.createdProductSetPaths.push(
testProductSet.createdProductSetPaths
);
});

after(async () => {
Expand Down
Loading