@@ -15,7 +15,7 @@ const authToken = require('./fixtures/authToken');
1515const { startServer} = require ( '../src' ) ;
1616const docker = require ( '../src/docker/docker' ) ;
1717const { initNetwork} = require ( '../src/docker/network' ) ;
18- const { getSecretsCollection, secretsInited} = require ( '../src/db/secrets' )
18+ const { getSecretsCollection, secretsInited} = require ( '../src/db/secrets' ) ;
1919
2020// create tar streams
2121const streamDockerImage = tar . pack ( path . join ( __dirname , 'fixtures' , 'docker-image-project' ) ) ;
@@ -29,6 +29,9 @@ const streamCompose = tar.pack(path.join(__dirname, 'fixtures', 'compose-project
2929const streamComposeUpdate = tar . pack ( path . join ( __dirname , 'fixtures' , 'compose-project' ) ) ;
3030const streamBrokenDocker = tar . pack ( path . join ( __dirname , 'fixtures' , 'broken-docker-project' ) ) ;
3131const streamBrokenNode = tar . pack ( path . join ( __dirname , 'fixtures' , 'broken-node-project' ) ) ;
32+ const streamBrokenTemplate = tar . pack ( path . join ( __dirname , 'fixtures' , 'broken-template-project' ) ) ;
33+ const streamBrokenCompose = tar . pack ( path . join ( __dirname , 'fixtures' , 'broken-compose-project' ) ) ;
34+ const streamBrokenComposeStart = tar . pack ( path . join ( __dirname , 'fixtures' , 'broken-compose-project-start' ) ) ;
3235const streamAdditionalLabels = tar . pack ( path . join ( __dirname , 'fixtures' , 'additional-labels' ) ) ;
3336const streamTemplate = tar . pack ( path . join ( __dirname , 'fixtures' , 'template-project' ) ) ;
3437
@@ -612,6 +615,78 @@ test('Should display error log for broken Node.js project', async done => {
612615 done ( ) ;
613616} ) ;
614617
618+ test ( 'Should display error log for project with broken template' , async done => {
619+ const options = Object . assign ( optionsBase , {
620+ payload : streamBrokenTemplate ,
621+ } ) ;
622+
623+ const response = await fastify . inject ( options ) ;
624+ // parse result into lines
625+ const result = response . payload
626+ . split ( '\n' )
627+ . filter ( l => l && l . length )
628+ . map ( line => JSON . parse ( line ) ) ;
629+
630+ // get last error
631+ const error = result . pop ( ) ;
632+
633+ // check response
634+ expect ( response . statusCode ) . toEqual ( 200 ) ;
635+ expect ( error . level ) . toEqual ( 'error' ) ;
636+ expect ( error . message ) . toEqual ( `Build failed! Couldn't find template: do-not-exist!` ) ;
637+
638+ // clean all exited containers
639+ const allContainers = await docker . listContainers ( { all : true } ) ;
640+ const exitedWithError = allContainers . filter ( c => c . Status . includes ( 'Exited (1)' ) ) ;
641+ await Promise . all ( exitedWithError . map ( c => docker . getContainer ( c . Id ) ) . map ( c => c . remove ( ) ) ) ;
642+
643+ done ( ) ;
644+ } ) ;
645+
646+ test ( 'Should display error log for broken compose project build' , async done => {
647+ const options = Object . assign ( optionsBase , {
648+ payload : streamBrokenCompose ,
649+ } ) ;
650+
651+ const response = await fastify . inject ( options ) ;
652+ // parse result into lines
653+ const result = response . payload
654+ . split ( '\n' )
655+ . filter ( l => l && l . length )
656+ . map ( line => JSON . parse ( line ) ) ;
657+
658+ // get last error
659+ const error = result . pop ( ) ;
660+
661+ // check response
662+ expect ( response . statusCode ) . toEqual ( 200 ) ;
663+ expect ( error . message ) . toEqual ( `Deployment failed! Docker-compose build exited with code: 1.` ) ;
664+
665+ done ( ) ;
666+ } ) ;
667+
668+ test ( 'Should display error log for broken compose project start' , async done => {
669+ const options = Object . assign ( optionsBase , {
670+ payload : streamBrokenComposeStart ,
671+ } ) ;
672+
673+ const response = await fastify . inject ( options ) ;
674+ // parse result into lines
675+ const result = response . payload
676+ . split ( '\n' )
677+ . filter ( l => l && l . length )
678+ . map ( line => JSON . parse ( line ) ) ;
679+
680+ // get last error
681+ const error = result . pop ( ) ;
682+
683+ // check response
684+ expect ( response . statusCode ) . toEqual ( 200 ) ;
685+ expect ( error . message ) . toEqual ( `Deployment failed! Docker-compose up exited with code: 1.` ) ;
686+
687+ done ( ) ;
688+ } ) ;
689+
615690test ( 'Should have additional labels' , async done => {
616691 const options = Object . assign ( optionsBase , {
617692 payload : streamAdditionalLabels ,
0 commit comments