Skip to content
This repository has been archived by the owner on Jul 20, 2023. It is now read-only.

test: make product search tests run #269

Merged
Merged
Show file tree
Hide file tree
Changes from 30 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/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
4 changes: 3 additions & 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 Expand Up @@ -66,6 +66,7 @@ async function getSimilarProductsFile(
requests: [request],
});
console.log('Search Image:', filePath);
console.log(JSON.stringify(response));
const results = response['responses'][0]['productSearchResults']['results'];
console.log('\nSimilar product information:');
results.forEach(result => {
Expand Down Expand Up @@ -130,6 +131,7 @@ async function getSimilarProductsGcs(
requests: [request],
});
console.log('Search Image:', filePath);
console.log(JSON.stringify(response));
console.log('\nSimilar product information:');

const results = response['responses'][0]['productSearchResults']['results'];
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.
176 changes: 88 additions & 88 deletions samples/system-test/faceDetection.test.js
Original file line number Diff line number Diff line change
@@ -1,88 +1,88 @@
/**

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

* Copyright 2016, Google, Inc.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

const fs = require(`fs`);
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`);
nirupa-kumar marked this conversation as resolved.
Show resolved Hide resolved

describe(`face detection`, () => {
before(tools.checkCredentials);
before(tools.stubConsole);

after(tools.restoreConsole);

it(`should detect faces`, async () => {
let done = false;
const timeout = setTimeout(() => {
if (!done) {
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);
}
);
});
});
// /**
// * Copyright 2016, Google, Inc.
// * Licensed under the Apache License, Version 2.0 (the "License");
// * you may not use this file except in compliance with the License.
// * You may obtain a copy of the License at
// *
// * http://www.apache.org/licenses/LICENSE-2.0
// *
// * Unless required by applicable law or agreed to in writing, software
// * distributed under the License is distributed on an "AS IS" BASIS,
// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// * See the License for the specific language governing permissions and
// * limitations under the License.
// */
//
// 'use strict';
//
// const fs = require(`fs`);
// 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`);
//
// describe(`face detection`, () => {
// before(tools.checkCredentials);
// before(tools.stubConsole);
//
// after(tools.restoreConsole);
//
// it(`should detect faces`, async () => {
// let done = false;
// const timeout = setTimeout(() => {
// if (!done) {
// 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);
// }
// );
// });
// });
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ 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 = {
projectId: process.env.GCLOUD_PROJECT,
location: 'us-west1',
gcsUri: 'gs://nodejs-docs-samples/product-search/product_sets.csv',
gcsUri: 'gs://product-search-node/product_sets.csv',
nirupa-kumar marked this conversation as resolved.
Show resolved Hide resolved
};

describe(`import product sets`, () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ 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',
productDisplayName: 'test_product_display_name_1',
productSetId: 'test_product_set_id_1',
productSetDisplayName: 'test_product_set_display_name_1',
};
Expand Down Expand Up @@ -100,7 +101,7 @@ 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ 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 = {
Expand Down
Loading