Skip to content

Commit 69715c5

Browse files
authored
test: cleanup resources from tests (#655)
Fixes #652 🦕
1 parent eeb6a5a commit 69715c5

3 files changed

+45
-0
lines changed

translate/test/v3/translate_batch_translate_text.test.js

+15
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,20 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
2525

2626
const REGION_TAG = 'translate_batch_translate_text';
2727

28+
async function clearBucket(projectId, storage, bucketUuid) {
29+
const options = {
30+
prefix: `translation-${bucketUuid}/BATCH_TRANSLATE_WITH_GLOS_OUTPUT/`,
31+
delimeter: '/',
32+
};
33+
34+
const bucket = await storage.bucket(projectId);
35+
const [files] = await bucket.getFiles(options);
36+
const length = files.length;
37+
if (length > 0) {
38+
await Promise.all(files.map(file => file.delete()));
39+
}
40+
}
41+
2842
describe(REGION_TAG, () => {
2943
const translationClient = new TranslationServiceClient();
3044
const location = 'us-central1';
@@ -51,6 +65,7 @@ describe(REGION_TAG, () => {
5165
it('should batch translate the input text', async function () {
5266
this.retries(3);
5367
const projectId = await translationClient.getProjectId();
68+
await clearBucket(projectId, storage, bucketUuid);
5469
const inputUri = 'gs://cloud-samples-data/translation/text.txt';
5570

5671
const outputUri = `gs://${projectId}/${bucketName}`;

translate/test/v3/translate_batch_translate_text_with_glossary_and_model.test.js

+15
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,20 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
2525

2626
const REGION_TAG = 'translate_batch_translate_text_with_glossary_and_model';
2727

28+
async function clearBucket(projectId, storage, bucketUuid) {
29+
const options = {
30+
prefix: `translation-${bucketUuid}/BATCH_TRANSLATE_WITH_GLOS_OUTPUT/`,
31+
delimeter: '/',
32+
};
33+
34+
const bucket = await storage.bucket(projectId);
35+
const [files] = await bucket.getFiles(options);
36+
const length = files.length;
37+
if (length > 0) {
38+
await Promise.all(files.map(file => file.delete()));
39+
}
40+
}
41+
2842
describe(REGION_TAG, () => {
2943
const translationClient = new TranslationServiceClient();
3044
const location = 'us-central1';
@@ -75,6 +89,7 @@ describe(REGION_TAG, () => {
7589
it('should batch translate the input text with a glossary', async function () {
7690
this.retries(3);
7791
const projectId = await translationClient.getProjectId();
92+
await clearBucket(projectId, storage, bucketUuid);
7893
const inputUri =
7994
'gs://cloud-samples-data/translation/text_with_custom_model_and_glossary.txt';
8095

translate/test/v3/translate_batch_translate_text_with_model.test.js

+15
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,20 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
2525

2626
const REGION_TAG = 'translate_batch_translate_text_with_model';
2727

28+
async function clearBucket(projectId, storage, bucketUuid) {
29+
const options = {
30+
prefix: `translation-${bucketUuid}/BATCH_TRANSLATE_WITH_GLOS_OUTPUT/`,
31+
delimeter: '/',
32+
};
33+
34+
const bucket = await storage.bucket(projectId);
35+
const [files] = await bucket.getFiles(options);
36+
const length = files.length;
37+
if (length > 0) {
38+
await Promise.all(files.map(file => file.delete()));
39+
}
40+
}
41+
2842
describe(REGION_TAG, () => {
2943
const translationClient = new TranslationServiceClient();
3044
const location = 'us-central1';
@@ -53,6 +67,7 @@ describe(REGION_TAG, () => {
5367
it('should batch translate the input text with a model', async function () {
5468
this.retries(3);
5569
const projectId = await translationClient.getProjectId();
70+
await clearBucket(projectId, storage, bucketUuid);
5671
const inputUri =
5772
'gs://cloud-samples-data/translation/custom_model_text.txt';
5873

0 commit comments

Comments
 (0)