From 7e32e206c6f7db57b8ed15de5227e4f9ee6d5096 Mon Sep 17 00:00:00 2001 From: Noah Negrey Date: Tue, 29 Oct 2019 13:14:38 -0600 Subject: [PATCH] test: address flaky v3 tests, by using unique identifiers (#366) --- .../translate_batch_translate_text_with_glossary.test.js | 5 ++--- ...te_batch_translate_text_with_glossary_and_model.test.js | 2 +- samples/test/v3/translate_create_glossary.test.js | 7 +++---- samples/test/v3/translate_delete_glossary.test.js | 3 ++- samples/test/v3/translate_get_glossary.test.js | 5 +++-- samples/test/v3/translate_list_glossary.test.js | 2 +- .../test/v3/translate_translate_text_with_glossary.test.js | 3 ++- ...ranslate_translate_text_with_glossary_and_model.test.js | 3 ++- 8 files changed, 16 insertions(+), 14 deletions(-) diff --git a/samples/test/v3/translate_batch_translate_text_with_glossary.test.js b/samples/test/v3/translate_batch_translate_text_with_glossary.test.js index 43cbb38b..cd66d2ee 100644 --- a/samples/test/v3/translate_batch_translate_text_with_glossary.test.js +++ b/samples/test/v3/translate_batch_translate_text_with_glossary.test.js @@ -28,7 +28,7 @@ const REGION_TAG = 'translate_batch_translate_text_with_glossary'; describe(REGION_TAG, () => { const translationClient = new TranslationServiceClient(); const location = 'us-central1'; - const glossaryId = 'my-fake_glossary'; + const glossaryId = `my_test_glossary_${uuid.v4()}`; const bucketUuid = uuid.v4(); const bucketName = `translation-${bucketUuid}/BATCH_TRANSLATION_OUTPUT/`; const storage = new Storage(); @@ -71,8 +71,7 @@ describe(REGION_TAG, () => { await operation.promise(); }); - // see: https://github.com/googleapis/nodejs-translate/issues/364 - it.skip('should batch translate the input text with a glossary [FLAKY]', async () => { + it('should batch translate the input text with a glossary', async () => { const projectId = await translationClient.getProjectId(); const inputUri = `gs://cloud-samples-data/translation/text.txt`; diff --git a/samples/test/v3/translate_batch_translate_text_with_glossary_and_model.test.js b/samples/test/v3/translate_batch_translate_text_with_glossary_and_model.test.js index bbc733c1..f79384d2 100644 --- a/samples/test/v3/translate_batch_translate_text_with_glossary_and_model.test.js +++ b/samples/test/v3/translate_batch_translate_text_with_glossary_and_model.test.js @@ -28,7 +28,7 @@ const REGION_TAG = 'translate_batch_translate_text_with_glossary_and_model'; describe(REGION_TAG, () => { const translationClient = new TranslationServiceClient(); const location = 'us-central1'; - const glossaryId = 'my-fake_glossary'; + const glossaryId = `my_test_glossary_${uuid.v4()}`; const modelId = 'TRL1218052175389786112'; const bucketUuid = uuid.v4(); const bucketName = `translation-${bucketUuid}/BATCH_TRANSLATION_OUTPUT/`; diff --git a/samples/test/v3/translate_create_glossary.test.js b/samples/test/v3/translate_create_glossary.test.js index 44f8ae0a..a5f973b6 100644 --- a/samples/test/v3/translate_create_glossary.test.js +++ b/samples/test/v3/translate_create_glossary.test.js @@ -17,6 +17,7 @@ const {assert} = require('chai'); const {TranslationServiceClient} = require('@google-cloud/translate'); const cp = require('child_process'); +const uuid = require('uuid'); const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); @@ -24,11 +25,11 @@ const REGION_TAG = 'translate_create_glossary'; describe(REGION_TAG, () => { const translationClient = new TranslationServiceClient(); + const glossaryId = `my_test_glossary_${uuid.v4()}`; + const location = 'us-central1'; it('should create a glossary', async function() { const projectId = await translationClient.getProjectId(); - const location = 'us-central1'; - const glossaryId = 'test-glossary'; const output = execSync( `node v3/${REGION_TAG}.js ${projectId} ${location} ${glossaryId}` ); @@ -40,8 +41,6 @@ describe(REGION_TAG, () => { after('cleanup for glossary create', async function() { const projectId = await translationClient.getProjectId(); - const location = 'us-central1'; - const glossaryId = 'test-glossary'; // Delete the glossary to clean up const request = { parent: `projects/${projectId}/locations/${location}`, diff --git a/samples/test/v3/translate_delete_glossary.test.js b/samples/test/v3/translate_delete_glossary.test.js index b5ce3f36..f516a907 100644 --- a/samples/test/v3/translate_delete_glossary.test.js +++ b/samples/test/v3/translate_delete_glossary.test.js @@ -17,6 +17,7 @@ const {assert} = require('chai'); const {TranslationServiceClient} = require('@google-cloud/translate'); const cp = require('child_process'); +const uuid = require('uuid'); const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); @@ -25,7 +26,7 @@ const REGION_TAG = 'translate_delete_glossary'; describe(REGION_TAG, () => { const translationClient = new TranslationServiceClient(); const location = 'us-central1'; - const glossaryId = 'glossary'; + const glossaryId = `my_test_glossary_${uuid.v4()}`; before(async function() { // Add a glossary to be deleted diff --git a/samples/test/v3/translate_get_glossary.test.js b/samples/test/v3/translate_get_glossary.test.js index eb7de3ed..47550b9c 100644 --- a/samples/test/v3/translate_get_glossary.test.js +++ b/samples/test/v3/translate_get_glossary.test.js @@ -17,6 +17,7 @@ const {assert} = require('chai'); const {TranslationServiceClient} = require('@google-cloud/translate'); const cp = require('child_process'); +const uuid = require('uuid'); const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); @@ -25,7 +26,7 @@ const REGION_TAG = 'translate_get_glossary'; describe(REGION_TAG, () => { const translationClient = new TranslationServiceClient(); const location = 'us-central1'; - const glossaryId = 'test-glossary'; + const glossaryId = `my_test_glossary_${uuid.v4()}`; before(async function() { // Add a glossary to get @@ -62,7 +63,7 @@ describe(REGION_TAG, () => { const output = execSync( `node v3/${REGION_TAG}.js ${projectId} ${location} ${glossaryId}` ); - assert.match(output, /test-glossary/); + assert.match(output, /my_test_glossary_/); }); after(async function() { diff --git a/samples/test/v3/translate_list_glossary.test.js b/samples/test/v3/translate_list_glossary.test.js index 8d6bab27..627688db 100644 --- a/samples/test/v3/translate_list_glossary.test.js +++ b/samples/test/v3/translate_list_glossary.test.js @@ -26,7 +26,7 @@ const REGION_TAG = 'translate_list_glossary'; describe(REGION_TAG, () => { const translationClient = new TranslationServiceClient(); const location = 'us-central1'; - const glossaryId = `test-glossary-${uuid.v4()}`; + const glossaryId = `my_test_glossary_${uuid.v4()}`; before(async function() { // Add a glossary to be deleted diff --git a/samples/test/v3/translate_translate_text_with_glossary.test.js b/samples/test/v3/translate_translate_text_with_glossary.test.js index e66eeef0..1bbb797c 100644 --- a/samples/test/v3/translate_translate_text_with_glossary.test.js +++ b/samples/test/v3/translate_translate_text_with_glossary.test.js @@ -16,6 +16,7 @@ const {assert} = require('chai'); const {TranslationServiceClient} = require('@google-cloud/translate'); +const uuid = require('uuid'); const cp = require('child_process'); const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); @@ -25,7 +26,7 @@ const REGION_TAG = 'translate_translate_text_with_glossary'; describe(REGION_TAG, () => { const translationClient = new TranslationServiceClient(); const location = 'us-central1'; - const glossaryId = 'test-glossary'; + const glossaryId = `my_test_glossary_${uuid.v4()}`; before(async function() { // Add a glossary to be translate with diff --git a/samples/test/v3/translate_translate_text_with_glossary_and_model.test.js b/samples/test/v3/translate_translate_text_with_glossary_and_model.test.js index 1f374831..37298469 100644 --- a/samples/test/v3/translate_translate_text_with_glossary_and_model.test.js +++ b/samples/test/v3/translate_translate_text_with_glossary_and_model.test.js @@ -16,6 +16,7 @@ const {assert} = require('chai'); const {TranslationServiceClient} = require('@google-cloud/translate'); +const uuid = require('uuid'); const cp = require('child_process'); const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); @@ -25,7 +26,7 @@ const REGION_TAG = 'translate_translate_text_with_glossary_and_model'; describe(REGION_TAG, () => { const translationClient = new TranslationServiceClient(); const location = 'us-central1'; - const glossaryId = 'test-glossary'; + const glossaryId = `my_test_glossary_${uuid.v4()}`; const modelId = 'TRL1218052175389786112'; before(async function() {