Skip to content

Commit

Permalink
test: ensure output dir is empty (#637)
Browse files Browse the repository at this point in the history
  • Loading branch information
munkhuushmgl authored and Ace Nassri committed Nov 17, 2022
1 parent ac37317 commit 92bb256
Showing 1 changed file with 17 additions and 2 deletions.
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';

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 @@ -71,9 +85,10 @@ describe(REGION_TAG, () => {
await operation.promise();
});

it('should batch translate the input text with a glossary', async function () {
this.retries(3);
it('should batch translate the input text with a glossary', async () => {
const projectId = await translationClient.getProjectId();
// make sure the bucket is empty.
await clearBucket(projectId, storage, bucketUuid);
const inputUri = 'gs://cloud-samples-data/translation/text.txt';

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

0 comments on commit 92bb256

Please sign in to comment.