Skip to content

Commit

Permalink
test: address flaky v3 tests, by using unique identifiers (#366)
Browse files Browse the repository at this point in the history
  • Loading branch information
nnegrey authored and Ace Nassri committed Nov 17, 2022
1 parent 906d7ea commit d74ecc2
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/`;
Expand Down
7 changes: 3 additions & 4 deletions translate/test/v3/translate_create_glossary.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,19 @@
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'});

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}`
);
Expand All @@ -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}`,
Expand Down
3 changes: 2 additions & 1 deletion translate/test/v3/translate_delete_glossary.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'});

Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions translate/test/v3/translate_get_glossary.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'});

Expand All @@ -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
Expand Down Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion translate/test/v3/translate_list_glossary.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'});
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'});
Expand All @@ -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() {
Expand Down

0 comments on commit d74ecc2

Please sign in to comment.