Skip to content

Commit

Permalink
test: cleanup resources from tests (#655)
Browse files Browse the repository at this point in the history

Fixes #652  🦕
  • Loading branch information
munkhuushmgl authored and Ace Nassri committed Nov 17, 2022
1 parent 2578dce commit fb1c017
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
15 changes: 15 additions & 0 deletions translate/test/v3/translate_batch_translate_text.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});

const REGION_TAG = 'translate_batch_translate_text';

async function clearBucket(projectId, storage, bucketUuid) {
const options = {
prefix: `translation-${bucketUuid}/BATCH_TRANSLATE_WITH_GLOS_OUTPUT/`,
delimeter: '/',
};

const bucket = await storage.bucket(projectId);
const [files] = await bucket.getFiles(options);
const length = files.length;
if (length > 0) {
await Promise.all(files.map(file => file.delete()));
}
}

describe(REGION_TAG, () => {
const translationClient = new TranslationServiceClient();
const location = 'us-central1';
Expand All @@ -51,6 +65,7 @@ describe(REGION_TAG, () => {
it('should batch translate the input text', async function () {
this.retries(3);
const projectId = await translationClient.getProjectId();
await clearBucket(projectId, storage, bucketUuid);
const inputUri = 'gs://cloud-samples-data/translation/text.txt';

const outputUri = `gs://${projectId}/${bucketName}`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});

const REGION_TAG = 'translate_batch_translate_text_with_glossary_and_model';

async function clearBucket(projectId, storage, bucketUuid) {
const options = {
prefix: `translation-${bucketUuid}/BATCH_TRANSLATE_WITH_GLOS_OUTPUT/`,
delimeter: '/',
};

const bucket = await storage.bucket(projectId);
const [files] = await bucket.getFiles(options);
const length = files.length;
if (length > 0) {
await Promise.all(files.map(file => file.delete()));
}
}

describe(REGION_TAG, () => {
const translationClient = new TranslationServiceClient();
const location = 'us-central1';
Expand Down Expand Up @@ -75,6 +89,7 @@ describe(REGION_TAG, () => {
it('should batch translate the input text with a glossary', async function () {
this.retries(3);
const projectId = await translationClient.getProjectId();
await clearBucket(projectId, storage, bucketUuid);
const inputUri =
'gs://cloud-samples-data/translation/text_with_custom_model_and_glossary.txt';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});

const REGION_TAG = 'translate_batch_translate_text_with_model';

async function clearBucket(projectId, storage, bucketUuid) {
const options = {
prefix: `translation-${bucketUuid}/BATCH_TRANSLATE_WITH_GLOS_OUTPUT/`,
delimeter: '/',
};

const bucket = await storage.bucket(projectId);
const [files] = await bucket.getFiles(options);
const length = files.length;
if (length > 0) {
await Promise.all(files.map(file => file.delete()));
}
}

describe(REGION_TAG, () => {
const translationClient = new TranslationServiceClient();
const location = 'us-central1';
Expand Down Expand Up @@ -53,6 +67,7 @@ describe(REGION_TAG, () => {
it('should batch translate the input text with a model', async function () {
this.retries(3);
const projectId = await translationClient.getProjectId();
await clearBucket(projectId, storage, bucketUuid);
const inputUri =
'gs://cloud-samples-data/translation/custom_model_text.txt';

Expand Down

0 comments on commit fb1c017

Please sign in to comment.