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

Commit

Permalink
fix: (tests): Use real service to validate expectations. (#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenplusplus authored and JustinBeckwith committed Aug 31, 2018
1 parent d73b519 commit 3e72501
Showing 1 changed file with 45 additions and 12 deletions.
57 changes: 45 additions & 12 deletions samples/system-test/detect.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ const test = require(`ava`);
const tools = require(`@google-cloud/nodejs-repo-tools`);
const uuid = require(`uuid`);

const vision = require('@google-cloud/vision');
const client = new vision.ImageAnnotatorClient();

const bucketName = `nodejs-docs-samples-test-${uuid.v4()}`;
const cmd = `node detect.js`;
const cwd = path.join(__dirname, `..`);
Expand Down Expand Up @@ -195,25 +198,55 @@ test(`should detect crop hints in a remote file`, async t => {

test(`should detect similar web images in a local file`, async t => {
const output = await tools.runAsync(`${cmd} web ${files[5].localPath}`, cwd);
t.true(output.includes('Full matches found:'));
t.true(output.includes('Partial matches found:'));
t.true(output.includes('Web entities found:'));
t.true(output.includes('Description: Google Cloud Platform'));
t.true(output.includes('Best guess labels found'));
t.true(output.includes('Label:'));

const [results] = await client.webDetection(files[5].localPath);
const webDetection = results[0].webDetection;

if (webDetection.fullMatchingImages.length) {
t.true(output.includes('Full matches found:'));
}

if (webDetection.partialMatchingImages.length) {
t.true(output.includes('Partial matches found:'));
}

if (webDetection.webEntities.length) {
t.true(output.includes('Web entities found:'));
t.true(output.includes('Description: Google Cloud Platform'));
}

if (webDetection.bestGuessLabels.length) {
t.true(output.includes('Best guess labels found'));
t.true(output.includes('Label:'));
}
});

test(`should detect similar web images in a remote file`, async t => {
const output = await tools.runAsync(
`${cmd} web-gcs ${bucketName} ${files[5].name}`,
cwd
);
t.true(output.includes('Full matches found:'));
t.true(output.includes('Partial matches found:'));
t.true(output.includes('Web entities found:'));
t.true(output.includes('Description: Google Cloud Platform'));
t.true(output.includes('Best guess labels found'));
t.true(output.includes('Label:'));

const [results] = await client.webDetection(`gs://${bucketName}/${files[5].name}`);
const webDetection = results[0].webDetection;

if (webDetection.fullMatchingImages.length) {
t.true(output.includes('Full matches found:'));
}

if (webDetection.partialMatchingImages.length) {
t.true(output.includes('Partial matches found:'));
}

if (webDetection.webEntities.length) {
t.true(output.includes('Web entities found:'));
t.true(output.includes('Description: Google Cloud Platform'));
}

if (webDetection.bestGuessLabels.length) {
t.true(output.includes('Best guess labels found'));
t.true(output.includes('Label:'));
}
});

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

0 comments on commit 3e72501

Please sign in to comment.