@@ -25,6 +25,20 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
25
25
26
26
const REGION_TAG = 'translate_batch_translate_text_with_glossary' ;
27
27
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
+
28
42
describe ( REGION_TAG , ( ) => {
29
43
const translationClient = new TranslationServiceClient ( ) ;
30
44
const location = 'us-central1' ;
@@ -71,9 +85,10 @@ describe(REGION_TAG, () => {
71
85
await operation . promise ( ) ;
72
86
} ) ;
73
87
74
- it ( 'should batch translate the input text with a glossary' , async function ( ) {
75
- this . retries ( 3 ) ;
88
+ it ( 'should batch translate the input text with a glossary' , async ( ) => {
76
89
const projectId = await translationClient . getProjectId ( ) ;
90
+ // make sure the bucket is empty.
91
+ await clearBucket ( projectId , storage , bucketUuid ) ;
77
92
const inputUri = 'gs://cloud-samples-data/translation/text.txt' ;
78
93
79
94
const outputUri = `gs://${ projectId } /${ bucketName } ` ;
0 commit comments