Skip to content

Commit a0ab1c5

Browse files
stephenplusplusJustinBeckwith
authored andcommitted
fix: (tests): Use real service to validate expectations. (#182)
1 parent d74b2c8 commit a0ab1c5

File tree

1 file changed

+45
-12
lines changed

1 file changed

+45
-12
lines changed

vision/samples/system-test/detect.test.js

+45-12
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ const test = require(`ava`);
2121
const tools = require(`@google-cloud/nodejs-repo-tools`);
2222
const uuid = require(`uuid`);
2323

24+
const vision = require('@google-cloud/vision');
25+
const client = new vision.ImageAnnotatorClient();
26+
2427
const bucketName = `nodejs-docs-samples-test-${uuid.v4()}`;
2528
const cmd = `node detect.js`;
2629
const cwd = path.join(__dirname, `..`);
@@ -195,25 +198,55 @@ test(`should detect crop hints in a remote file`, async t => {
195198

196199
test(`should detect similar web images in a local file`, async t => {
197200
const output = await tools.runAsync(`${cmd} web ${files[5].localPath}`, cwd);
198-
t.true(output.includes('Full matches found:'));
199-
t.true(output.includes('Partial matches found:'));
200-
t.true(output.includes('Web entities found:'));
201-
t.true(output.includes('Description: Google Cloud Platform'));
202-
t.true(output.includes('Best guess labels found'));
203-
t.true(output.includes('Label:'));
201+
202+
const [results] = await client.webDetection(files[5].localPath);
203+
const webDetection = results[0].webDetection;
204+
205+
if (webDetection.fullMatchingImages.length) {
206+
t.true(output.includes('Full matches found:'));
207+
}
208+
209+
if (webDetection.partialMatchingImages.length) {
210+
t.true(output.includes('Partial matches found:'));
211+
}
212+
213+
if (webDetection.webEntities.length) {
214+
t.true(output.includes('Web entities found:'));
215+
t.true(output.includes('Description: Google Cloud Platform'));
216+
}
217+
218+
if (webDetection.bestGuessLabels.length) {
219+
t.true(output.includes('Best guess labels found'));
220+
t.true(output.includes('Label:'));
221+
}
204222
});
205223

206224
test(`should detect similar web images in a remote file`, async t => {
207225
const output = await tools.runAsync(
208226
`${cmd} web-gcs ${bucketName} ${files[5].name}`,
209227
cwd
210228
);
211-
t.true(output.includes('Full matches found:'));
212-
t.true(output.includes('Partial matches found:'));
213-
t.true(output.includes('Web entities found:'));
214-
t.true(output.includes('Description: Google Cloud Platform'));
215-
t.true(output.includes('Best guess labels found'));
216-
t.true(output.includes('Label:'));
229+
230+
const [results] = await client.webDetection(`gs://${bucketName}/${files[5].name}`);
231+
const webDetection = results[0].webDetection;
232+
233+
if (webDetection.fullMatchingImages.length) {
234+
t.true(output.includes('Full matches found:'));
235+
}
236+
237+
if (webDetection.partialMatchingImages.length) {
238+
t.true(output.includes('Partial matches found:'));
239+
}
240+
241+
if (webDetection.webEntities.length) {
242+
t.true(output.includes('Web entities found:'));
243+
t.true(output.includes('Description: Google Cloud Platform'));
244+
}
245+
246+
if (webDetection.bestGuessLabels.length) {
247+
t.true(output.includes('Best guess labels found'));
248+
t.true(output.includes('Label:'));
249+
}
217250
});
218251

219252
test(`should detect web entities with geo metadata in local file`, async t => {

0 commit comments

Comments
 (0)