@@ -32,6 +32,8 @@ const generateContainerConfig = ({ name, username, project, url }) => ({
3232 } ,
3333} ) ;
3434
35+ const testUrl = 'rmtest.example.com' ;
36+
3537beforeAll ( async ( ) => {
3638 // start server
3739 const port = await getPort ( ) ;
@@ -50,6 +52,17 @@ beforeAll(async () => {
5052 } ) ;
5153 const container = await docker . createContainer ( containerConfig ) ;
5254 await container . start ( ) ;
55+ // create test container with url to remove
56+ // second project container
57+ const urlContainerConfig = generateContainerConfig ( {
58+ name : 'rmtest12' ,
59+ username : 'admin' ,
60+ project : 'rmtest12' ,
61+ baseName : 'exo-admin-rmtest12' ,
62+ url : testUrl ,
63+ } ) ;
64+ const urlContainer = await docker . createContainer ( urlContainerConfig ) ;
65+ await urlContainer . start ( ) ;
5366 // create test project to remove
5467 // first project container
5568 const prjContainerConfig1 = generateContainerConfig ( {
@@ -88,6 +101,22 @@ test('Should remove current deployment', async () => {
88101 expect ( exContainer ) . toBeUndefined ( ) ;
89102} ) ;
90103
104+ test ( 'Should remove container by url' , async ( ) => {
105+ // options base
106+ const options = Object . assign ( { } , baseOptions , { url : `/remove/${ encodeURIComponent ( testUrl ) } ` } ) ;
107+
108+ const response = await fastify . inject ( options ) ;
109+ // check response
110+ expect ( response . statusCode ) . toEqual ( 204 ) ;
111+
112+ // check docker services
113+ const allContainers = await docker . listContainers ( ) ;
114+ const urlContainers = allContainers . filter ( ( c ) =>
115+ c . Labels [ `traefik.http.routers.${ c . Labels [ 'exoframe.deployment' ] } .rule` ] . includes ( testUrl )
116+ ) ;
117+ expect ( urlContainers . length ) . toEqual ( 0 ) ;
118+ } ) ;
119+
91120test ( 'Should remove current project' , async ( ) => {
92121 // options base
93122 const options = Object . assign ( { } , baseOptions , { url : `/remove/${ projectName } ` } ) ;
0 commit comments