1515 */
1616
1717import { afterEach , beforeEach , describe , expect , it , jest } from '@jest/globals' ;
18+ import * as fs from 'fs' ;
1819import path from 'path' ;
1920import * as io from '@actions/io' ;
2021import osm = require( 'os' ) ;
22+ import * as rimraf from 'rimraf' ;
2123
2224import { Docker } from '../../src/docker/docker' ;
2325import { Exec } from '../../src/exec' ;
2426
27+ import { ConfigFile } from '../../src/types/docker' ;
28+
29+ const fixturesDir = path . join ( __dirname , '..' , 'fixtures' ) ;
30+
31+ // prettier-ignore
32+ const tmpDir = path . join ( process . env . TEMP || '/tmp' , 'docker-jest' ) ;
33+
2534beforeEach ( ( ) => {
2635 jest . clearAllMocks ( ) ;
2736} ) ;
2837
38+ afterEach ( function ( ) {
39+ rimraf . sync ( tmpDir ) ;
40+ } ) ;
41+
2942describe ( 'configDir' , ( ) => {
3043 const originalEnv = process . env ;
3144 beforeEach ( ( ) => {
@@ -48,6 +61,45 @@ describe('configDir', () => {
4861 } ) ;
4962} ) ;
5063
64+ describe ( 'configFile' , ( ) => {
65+ const originalEnv = process . env ;
66+ beforeEach ( ( ) => {
67+ jest . resetModules ( ) ;
68+ if ( ! fs . existsSync ( tmpDir ) ) {
69+ fs . mkdirSync ( tmpDir , { recursive : true } ) ;
70+ }
71+ process . env = {
72+ ...originalEnv ,
73+ DOCKER_CONFIG : tmpDir
74+ } ;
75+ } ) ;
76+ afterEach ( ( ) => {
77+ process . env = originalEnv ;
78+ } ) ;
79+ it ( 'auths' , async ( ) => {
80+ fs . copyFileSync ( path . join ( fixturesDir , 'docker-config-auths.json' ) , path . join ( tmpDir , 'config.json' ) ) ;
81+ expect ( Docker . configFile ( ) ) . toEqual ( {
82+ auths : {
83+ 'https://index.docker.io/v1/' : {
84+ auth : 'am9lam9lOmhlbGxv' ,
85+ 86+ }
87+ }
88+ } as unknown as ConfigFile ) ;
89+ } ) ;
90+ it ( 'proxies' , async ( ) => {
91+ fs . copyFileSync ( path . join ( fixturesDir , 'docker-config-proxies.json' ) , path . join ( tmpDir , 'config.json' ) ) ;
92+ expect ( Docker . configFile ( ) ) . toEqual ( {
93+ proxies : {
94+ default : {
95+ httpProxy : 'http://127.0.0.1:3128' ,
96+ httpsProxy : 'http://127.0.0.1:3128'
97+ }
98+ }
99+ } as unknown as ConfigFile ) ;
100+ } ) ;
101+ } ) ;
102+
51103describe ( 'isAvailable' , ( ) => {
52104 it ( 'cli' , async ( ) => {
53105 const ioWhichSpy = jest . spyOn ( io , 'which' ) ;
0 commit comments