11const chai = require ( 'chai' ) ;
22const sinon = require ( 'sinon' ) ;
33const sinonChai = require ( 'sinon-chai' ) ;
4+ const { shutdownGracefully} = require ( "../lib/helpers" ) ;
45const proxyquire = require ( 'proxyquire' ) . noCallThru ( ) ;
56
67const expect = chai . expect ;
@@ -57,12 +58,10 @@ describe('addNewMask', () => {
5758 stubGot . post . resolves ( { statusCode : 201 } ) ;
5859
5960 const { updateMasks, exitHandler } = proxyquire ( '../lib/addNewMask' , {
60- '@codefresh-io/cf-telemetry/init' : {
61- terminate : ( ) => ( {
62- finally : callback => callback ( ) ,
63- } )
61+ './helpers' : {
62+ getServerAddress : stubGetServerAddress ,
63+ shutdownGracefully,
6464 } ,
65- './helpers' : { getServerAddress : stubGetServerAddress } ,
6665 } ) ;
6766 process . listeners ( 'exit' ) . forEach ( ( listener ) => {
6867 if ( listener === exitHandler ) {
@@ -82,16 +81,12 @@ describe('addNewMask', () => {
8281 it ( 'should fail if the server address is not available' , async ( ) => {
8382 stubGetServerAddress . rejects ( 'could not get server address' ) ;
8483 const { updateMasks, exitHandler } = proxyquire ( '../lib/addNewMask' , {
85- '@codefresh-io/cf-telemetry/init' : {
86- terminate : ( ) => ( {
87- finally : callback => callback ( ) ,
88- } )
89- } ,
9084 '@codefresh-io/cf-telemetry/logs' : {
9185 Logger : function ( ) { return stubLogger } ,
9286 } ,
9387 './helpers' : {
9488 getServerAddress : stubGetServerAddress ,
89+ shutdownGracefully,
9590 } ,
9691 } ) ;
9792 process . listeners ( 'exit' ) . forEach ( ( listener ) => {
@@ -107,16 +102,12 @@ describe('addNewMask', () => {
107102 it ( 'should fail if the server address is not valid URL' , async ( ) => {
108103 stubGetServerAddress . resolves ( 'foo' ) ;
109104 const { updateMasks, exitHandler } = proxyquire ( '../lib/addNewMask' , {
110- '@codefresh-io/cf-telemetry/init' : {
111- terminate : ( ) => ( {
112- finally : callback => callback ( ) ,
113- } )
114- } ,
115105 '@codefresh-io/cf-telemetry/logs' : {
116106 Logger : function ( ) { return stubLogger } ,
117107 } ,
118108 './helpers' : {
119109 getServerAddress : stubGetServerAddress ,
110+ shutdownGracefully,
120111 } ,
121112 } ) ;
122113 process . listeners ( 'exit' ) . forEach ( ( listener ) => {
@@ -137,15 +128,13 @@ describe('addNewMask', () => {
137128 body : 'Internal Server Error' ,
138129 } ) ;
139130 const { updateMasks, exitHandler } = proxyquire ( '../lib/addNewMask' , {
140- '@codefresh-io/cf-telemetry/init' : {
141- terminate : ( ) => ( {
142- finally : callback => callback ( ) ,
143- } )
144- } ,
145131 '@codefresh-io/cf-telemetry/logs' : {
146132 Logger : function ( ) { return stubLogger } ,
147133 } ,
148- './helpers' : { getServerAddress : stubGetServerAddress } ,
134+ './helpers' : {
135+ getServerAddress : stubGetServerAddress ,
136+ shutdownGracefully,
137+ } ,
149138 } ) ;
150139 process . listeners ( 'exit' ) . forEach ( ( listener ) => {
151140 if ( listener === exitHandler ) {
@@ -202,7 +191,10 @@ describe('addNewMask', () => {
202191 stubGetServerAddress . resolves ( serverAddress ) ;
203192 stubGot . post . resolves ( { statusCode : 201 } ) ;
204193 const { updateMasks, exitHandler } = proxyquire ( '../lib/addNewMask' , {
205- './helpers' : { getServerAddress : stubGetServerAddress } ,
194+ './helpers' : {
195+ getServerAddress : stubGetServerAddress ,
196+ shutdownGracefully,
197+ } ,
206198 } ) ;
207199 process . listeners ( 'exit' ) . forEach ( ( listener ) => {
208200 if ( listener === exitHandler ) {
0 commit comments