|
| 1 | +/** |
| 2 | + * Copyright 2017, Google, Inc. |
| 3 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | + * you may not use this file except in compliance with the License. |
| 5 | + * You may obtain a copy of the License at |
| 6 | + * |
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + * |
| 9 | + * Unless required by applicable law or agreed to in writing, software |
| 10 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | + * See the License for the specific language governing permissions and |
| 13 | + * limitations under the License. |
| 14 | + */ |
| 15 | + |
| 16 | +'use strict'; |
| 17 | + |
| 18 | +require(`../../system-test/_setup`); |
| 19 | + |
| 20 | +const path = require(`path`); |
| 21 | +const storage = require(`@google-cloud/storage`)(); |
| 22 | +const uuid = require(`uuid`); |
| 23 | + |
| 24 | +const bucketName = `nodejs-docs-samples-test-${uuid.v4()}`; |
| 25 | +const cmd = `node detect.js`; |
| 26 | +const cwd = path.join(__dirname, `..`); |
| 27 | +const files = [ |
| 28 | + `face_no_surprise.jpg`, |
| 29 | + `landmark.jpg`, |
| 30 | + `logos.png`, |
| 31 | + `text.jpg`, |
| 32 | + `wakeupcat.jpg` |
| 33 | +].map((name) => { |
| 34 | + return { |
| 35 | + name, |
| 36 | + localPath: path.resolve(path.join(__dirname, `../resources/${name}`)) |
| 37 | + }; |
| 38 | +}); |
| 39 | + |
| 40 | +test.before(async () => { |
| 41 | + const [bucket] = await storage.createBucket(bucketName); |
| 42 | + await Promise.all(files.map((file) => bucket.upload(file.localPath))); |
| 43 | +}); |
| 44 | + |
| 45 | +test.after.always(async () => { |
| 46 | + const bucket = storage.bucket(bucketName); |
| 47 | + await bucket.deleteFiles({ force: true }); |
| 48 | + await bucket.deleteFiles({ force: true }); // Try a second time... |
| 49 | + await bucket.delete(); |
| 50 | +}); |
| 51 | + |
| 52 | +test(`should detect faces in a local file`, async (t) => { |
| 53 | + const output = await runAsync(`${cmd} faces ${files[0].localPath}`, cwd); |
| 54 | + t.true(output.includes(`Faces:`)); |
| 55 | + t.true(output.includes(`Face #1:`)); |
| 56 | +}); |
| 57 | + |
| 58 | +test(`should detect faces in a remote file`, async (t) => { |
| 59 | + const output = await runAsync(`${cmd} faces-gcs ${bucketName} ${files[0].name}`, cwd); |
| 60 | + t.true(output.includes(`Faces:`)); |
| 61 | + t.true(output.includes(`Face #1:`)); |
| 62 | +}); |
| 63 | + |
| 64 | +test(`should detect labels in a local file`, async (t) => { |
| 65 | + const output = await runAsync(`${cmd} labels ${files[4].localPath}`, cwd); |
| 66 | + t.true(output.includes(`Labels:`)); |
| 67 | + t.true(output.includes(`cat`)); |
| 68 | +}); |
| 69 | + |
| 70 | +test(`should detect labels in a remote file`, async (t) => { |
| 71 | + const output = await runAsync(`${cmd} labels-gcs ${bucketName} ${files[4].name}`, cwd); |
| 72 | + t.true(output.includes(`Labels:`)); |
| 73 | + t.true(output.includes(`cat`)); |
| 74 | +}); |
| 75 | + |
| 76 | +test(`should detect landmarks in a local file`, async (t) => { |
| 77 | + const output = await runAsync(`${cmd} landmarks ${files[1].localPath}`, cwd); |
| 78 | + t.true(output.includes(`Landmarks:`)); |
| 79 | + t.true(output.includes(`Palace of Fine Arts`)); |
| 80 | +}); |
| 81 | + |
| 82 | +test(`should detect landmarks in a remote file`, async (t) => { |
| 83 | + const output = await runAsync(`${cmd} landmarks-gcs ${bucketName} ${files[1].name}`, cwd); |
| 84 | + t.true(output.includes(`Landmarks:`)); |
| 85 | + t.true(output.includes(`Palace of Fine Arts`)); |
| 86 | +}); |
| 87 | + |
| 88 | +test(`should detect text in a local file`, async (t) => { |
| 89 | + const output = await runAsync(`${cmd} text ${files[3].localPath}`, cwd); |
| 90 | + t.true(output.includes(`Text:`)); |
| 91 | + t.true(output.includes(`System Software Update`)); |
| 92 | +}); |
| 93 | + |
| 94 | +test(`should detect text in a remote file`, async (t) => { |
| 95 | + const output = await runAsync(`${cmd} text-gcs ${bucketName} ${files[3].name}`, cwd); |
| 96 | + t.true(output.includes(`Text:`)); |
| 97 | + t.true(output.includes(`System Software Update`)); |
| 98 | +}); |
| 99 | + |
| 100 | +test(`should detect logos in a local file`, async (t) => { |
| 101 | + const output = await runAsync(`${cmd} logos ${files[2].localPath}`, cwd); |
| 102 | + t.true(output.includes(`Logos:`)); |
| 103 | + t.true(output.includes(`Google`)); |
| 104 | +}); |
| 105 | + |
| 106 | +test(`should detect logos in a remote file`, async (t) => { |
| 107 | + const output = await runAsync(`${cmd} logos-gcs ${bucketName} ${files[2].name}`, cwd); |
| 108 | + t.true(output.includes(`Logos:`)); |
| 109 | + t.true(output.includes(`Google`)); |
| 110 | +}); |
| 111 | + |
| 112 | +test(`should detect properties in a local file`, async (t) => { |
| 113 | + const output = await runAsync(`${cmd} properties ${files[1].localPath}`, cwd); |
| 114 | + t.true(output.includes(`Colors:`)); |
| 115 | + t.true(output.split(`\n`).length > 4, `Multiple colors were detected.`); |
| 116 | +}); |
| 117 | + |
| 118 | +test(`should detect properties in a remote file`, async (t) => { |
| 119 | + const output = await runAsync(`${cmd} properties-gcs ${bucketName} ${files[1].name}`, cwd); |
| 120 | + t.true(output.includes(`Colors:`)); |
| 121 | + t.true(output.split(`\n`).length > 4, `Multiple colors were detected.`); |
| 122 | +}); |
| 123 | + |
| 124 | +test(`should detect safe-search in a local file`, async (t) => { |
| 125 | + const output = await runAsync(`${cmd} safe-search ${files[4].localPath}`, cwd); |
| 126 | + t.true(output.includes(`Medical:`)); |
| 127 | +}); |
| 128 | + |
| 129 | +test(`should detect safe-search in a remote file`, async (t) => { |
| 130 | + const output = await runAsync(`${cmd} safe-search-gcs ${bucketName} ${files[4].name}`, cwd); |
| 131 | + t.true(output.includes(`Medical:`)); |
| 132 | +}); |
0 commit comments