@@ -43,6 +43,16 @@ const outputUriForTemplate = `gs://${bucketName}/test-output-template/`;
4343const outputUriForAdHoc = `gs://${ bucketName } /test-output-adhoc/` ;
4444const outputUriForStaticOverlay = `gs://${ bucketName } /test-output-static-overlay/` ;
4545const outputUriForAnimatedOverlay = `gs://${ bucketName } /test-output-animated-overlay/` ;
46+ const outputDirForSetNumberImagesSpritesheet =
47+ 'test-output-set-number-spritesheet/' ;
48+ const outputUriForSetNumberImagesSpritesheet = `gs://${ bucketName } /${ outputDirForSetNumberImagesSpritesheet } ` ;
49+ const outputDirForPeriodicImagesSpritesheet =
50+ 'test-output-periodic-spritesheet/' ;
51+ const outputUriForPeriodicImagesSpritesheet = `gs://${ bucketName } /${ outputDirForPeriodicImagesSpritesheet } ` ;
52+ // Spritesheets are generated from the input video into the bucket directories above.
53+ // Spritesheets use the following file naming conventions:
54+ const smallSpriteSheetFileName = 'small-sprite-sheet0000000000.jpeg' ;
55+ const largeSpriteSheetFileName = 'large-sprite-sheet0000000000.jpeg' ;
4656
4757const cwd = path . join ( __dirname , '..' ) ;
4858const videoFile = `testdata/${ testFileName } ` ;
@@ -56,6 +66,16 @@ function wait(ms) {
5666 } ) ;
5767}
5868
69+ const checkFileExists = async function ( bucketName , fileName ) {
70+ const [ files ] = await storage . bucket ( bucketName ) . getFiles ( ) ;
71+ for ( let i = 0 ; i < files . length ; i ++ ) {
72+ if ( files [ i ] . name === fileName ) {
73+ return true ;
74+ }
75+ }
76+ return false ;
77+ } ;
78+
5979before ( async ( ) => {
6080 assert (
6181 process . env . GOOGLE_CLOUD_PROJECT_NUMBER ,
@@ -308,14 +328,6 @@ describe('Job with static overlay functions', () => {
308328 assert . ok ( output . includes ( jobName ) ) ;
309329 } ) ;
310330
311- it ( 'should show a list of jobs' , function ( ) {
312- const output = execSync ( `node listJobs.js ${ projectId } ${ location } ` , {
313- cwd,
314- } ) ;
315- const jobName = `projects/${ projectNumber } /locations/${ location } /jobs/${ this . staticOverlayJobId } ` ;
316- assert . ok ( output . includes ( jobName ) ) ;
317- } ) ;
318-
319331 it ( 'should check that the job succeeded' , async function ( ) {
320332 this . retries ( 5 ) ;
321333 await wait ( 90000 ) ;
@@ -356,21 +368,127 @@ describe('Job with animated overlay functions', () => {
356368 assert . ok ( output . includes ( jobName ) ) ;
357369 } ) ;
358370
359- it ( 'should show a list of jobs' , function ( ) {
360- const output = execSync ( `node listJobs.js ${ projectId } ${ location } ` , {
361- cwd,
362- } ) ;
363- const jobName = `projects/${ projectNumber } /locations/${ location } /jobs/${ this . animatedOverlayJobId } ` ;
371+ it ( 'should check that the job succeeded' , async function ( ) {
372+ this . retries ( 5 ) ;
373+ await wait ( 90000 ) ;
374+ const output = execSync (
375+ `node getJobState.js ${ projectId } ${ location } ${ this . animatedOverlayJobId } ` ,
376+ { cwd}
377+ ) ;
378+ assert . ok ( output . includes ( 'Job state: SUCCEEDED' ) ) ;
379+ } ) ;
380+ } ) ;
381+
382+ describe ( 'Job with set number of images spritesheet' , ( ) => {
383+ before ( function ( ) {
384+ const output = execSync (
385+ `node createJobWithSetNumberImagesSpritesheet.js ${ projectId } ${ location } ${ inputUri } ${ outputUriForSetNumberImagesSpritesheet } ` ,
386+ { cwd}
387+ ) ;
388+ assert . ok (
389+ output . includes ( `projects/${ projectNumber } /locations/${ location } /jobs/` )
390+ ) ;
391+ this . setNumberSpritesheetJobId = output . toString ( ) . split ( '/' ) . pop ( ) ;
392+ } ) ;
393+
394+ after ( function ( ) {
395+ const output = execSync (
396+ `node deleteJob.js ${ projectId } ${ location } ${ this . setNumberSpritesheetJobId } ` ,
397+ { cwd}
398+ ) ;
399+ assert . ok ( output . includes ( 'Deleted job' ) ) ;
400+ } ) ;
401+
402+ it ( 'should get a job' , function ( ) {
403+ const output = execSync (
404+ `node getJob.js ${ projectId } ${ location } ${ this . setNumberSpritesheetJobId } ` ,
405+ { cwd}
406+ ) ;
407+ const jobName = `projects/${ projectNumber } /locations/${ location } /jobs/${ this . setNumberSpritesheetJobId } ` ;
364408 assert . ok ( output . includes ( jobName ) ) ;
365409 } ) ;
366410
367411 it ( 'should check that the job succeeded' , async function ( ) {
368412 this . retries ( 5 ) ;
369413 await wait ( 90000 ) ;
370414 const output = execSync (
371- `node getJobState.js ${ projectId } ${ location } ${ this . animatedOverlayJobId } ` ,
415+ `node getJobState.js ${ projectId } ${ location } ${ this . setNumberSpritesheetJobId } ` ,
372416 { cwd}
373417 ) ;
374418 assert . ok ( output . includes ( 'Job state: SUCCEEDED' ) ) ;
375419 } ) ;
420+
421+ it ( 'should check that the spritesheet files exist in the bucket' , async ( ) => {
422+ assert . equal (
423+ await checkFileExists (
424+ bucketName ,
425+ `${ outputDirForSetNumberImagesSpritesheet } ${ smallSpriteSheetFileName } `
426+ ) ,
427+ true
428+ ) ;
429+ assert . equal (
430+ await checkFileExists (
431+ bucketName ,
432+ `${ outputDirForSetNumberImagesSpritesheet } ${ largeSpriteSheetFileName } `
433+ ) ,
434+ true
435+ ) ;
436+ } ) ;
437+ } ) ;
438+
439+ describe ( 'Job with periodic images spritesheet' , ( ) => {
440+ before ( function ( ) {
441+ const output = execSync (
442+ `node createJobWithPeriodicImagesSpritesheet.js ${ projectId } ${ location } ${ inputUri } ${ outputUriForPeriodicImagesSpritesheet } ` ,
443+ { cwd}
444+ ) ;
445+ assert . ok (
446+ output . includes ( `projects/${ projectNumber } /locations/${ location } /jobs/` )
447+ ) ;
448+ this . periodicSpritesheetJobId = output . toString ( ) . split ( '/' ) . pop ( ) ;
449+ } ) ;
450+
451+ after ( function ( ) {
452+ const output = execSync (
453+ `node deleteJob.js ${ projectId } ${ location } ${ this . periodicSpritesheetJobId } ` ,
454+ { cwd}
455+ ) ;
456+ assert . ok ( output . includes ( 'Deleted job' ) ) ;
457+ } ) ;
458+
459+ it ( 'should get a job' , function ( ) {
460+ const output = execSync (
461+ `node getJob.js ${ projectId } ${ location } ${ this . periodicSpritesheetJobId } ` ,
462+ { cwd}
463+ ) ;
464+ const jobName = `projects/${ projectNumber } /locations/${ location } /jobs/${ this . periodicSpritesheetJobId } ` ;
465+ assert . ok ( output . includes ( jobName ) ) ;
466+ } ) ;
467+
468+ it ( 'should check that the job succeeded' , async function ( ) {
469+ this . retries ( 5 ) ;
470+ await wait ( 90000 ) ;
471+ const output = execSync (
472+ `node getJobState.js ${ projectId } ${ location } ${ this . periodicSpritesheetJobId } ` ,
473+ { cwd}
474+ ) ;
475+ assert . ok ( output . includes ( 'Job state: SUCCEEDED' ) ) ;
476+ } ) ;
477+
478+ it ( 'should check that the spritesheet files exist in the bucket' , async ( ) => {
479+ assert . equal (
480+ await checkFileExists (
481+ bucketName ,
482+ `${ outputDirForPeriodicImagesSpritesheet } ${ smallSpriteSheetFileName } `
483+ ) ,
484+ true
485+ ) ;
486+ assert . equal (
487+ await checkFileExists (
488+ bucketName ,
489+ `${ outputDirForPeriodicImagesSpritesheet } ${ largeSpriteSheetFileName } `
490+ ) ,
491+ true
492+ ) ;
493+ } ) ;
376494} ) ;
0 commit comments