11import { Context } from '../src/context' ;
2- import { runCompose , runAction , runCleanup , ComposeError } from '../src/compose' ;
2+ import {
3+ runCompose ,
4+ runAction ,
5+ runCleanup ,
6+ ComposeError ,
7+ composeCommand
8+ } from '../src/compose' ;
39import { mocked } from 'jest-mock' ;
410import { exec } from '@actions/exec' ;
511
@@ -11,12 +17,61 @@ const OLD_ENV = process.env;
1117beforeEach ( ( ) => {
1218 process . env = { ...OLD_ENV } ;
1319 mocked ( exec ) . mockReset ( ) ;
20+ composeCommand . init ( ) ; // In most tests we are not interested in testing the docker-compose/docker compose fallback logic
1421} ) ;
1522
1623afterEach ( ( ) => {
1724 process . env = OLD_ENV ;
1825} ) ;
1926
27+ describe ( 'fall back to docker compose' , ( ) => {
28+ test ( 'basic command' , async ( ) => {
29+ composeCommand . reset ( ) ; // Here we are interested in the fallback logic
30+ const command = 'build' ;
31+ const projectName = 'test-name' ;
32+ const context : Context = {
33+ composeFiles : [ 'docker-compose.ci.yml' ] ,
34+ serviceName : 'test' ,
35+ composeCommand : 'up' ,
36+ composeArguments : [ '--abort-on-container-exit' ] ,
37+ runCommand : [ ] ,
38+ build : true ,
39+ buildArgs : [ ] ,
40+ registryCache : 'hub.artifactor.ee' ,
41+ push : false ,
42+ postCommand : [ 'down --remove-orphans --volumes' , 'rm -f' ] ,
43+ isPost : false ,
44+ projectName : projectName
45+ } ;
46+
47+ const mockExec = mocked ( exec ) ;
48+ mockExec . mockRejectedValueOnce ( new Error ( 'docker-compose not found' ) ) ;
49+ mockExec . mockResolvedValue ( 0 ) ;
50+
51+ await runCompose ( command , [ ] , context ) ;
52+
53+ const calls = mockExec . mock . calls ;
54+ expect ( calls . length ) . toBe ( 2 ) ;
55+
56+ const expectedArgs : string [ ] = [
57+ '-f' ,
58+ context . composeFiles [ 0 ] ,
59+ '-p' ,
60+ projectName ,
61+ command
62+ ] ;
63+ expect ( mockExec ) . toHaveBeenNthCalledWith ( 1 , 'docker-compose' , [
64+ '--version'
65+ ] ) ;
66+ expect ( mockExec ) . toHaveBeenNthCalledWith (
67+ 2 ,
68+ 'docker compose' ,
69+ expectedArgs ,
70+ undefined
71+ ) ;
72+ } ) ;
73+ } ) ;
74+
2075describe ( 'run docker-compose' , ( ) => {
2176 test ( 'basic command' , async ( ) => {
2277 const command = 'build' ;
0 commit comments