@@ -236,7 +236,12 @@ describe('gpg tests', () => {
236236 process . env [ 'RUNNER_TEMP' ] = tempDir ;
237237 } ) ;
238238
239- it . each ( [ 'success' , 'import failure' , 'verification failure' ] ) (
239+ it . each ( [
240+ 'success' ,
241+ 'import failure' ,
242+ 'verification failure' ,
243+ 'gpgconf unavailable'
244+ ] ) (
240245 'uses a short macOS home or RUNNER_TEMP elsewhere and cleans up after %s' ,
241246 async outcome => {
242247 const longRunnerTemp = path . join (
@@ -257,9 +262,16 @@ describe('gpg tests', () => {
257262 fs . writeFileSync ( signaturePath , 'signature' ) ;
258263 ( tc . downloadTool as jest . Mock < any > ) . mockResolvedValue ( signaturePath ) ;
259264 ( exec . exec as jest . Mock < any > ) . mockImplementation (
260- async ( _command : string , args : string [ ] ) => {
265+ async ( command : string , args : string [ ] ) => {
261266 gpgHome = path . join ( expectedParent , path . posix . basename ( args [ 1 ] ) ) ;
262267 expect ( args [ 1 ] ) . toBe ( gpg . toGpgPath ( gpgHome ) ) ;
268+ if ( command === 'gpgconf' ) {
269+ expect ( fs . existsSync ( gpgHome ) ) . toBe ( true ) ;
270+ if ( outcome === 'gpgconf unavailable' ) {
271+ throw new Error ( 'gpgconf unavailable' ) ;
272+ }
273+ return 0 ;
274+ }
263275 if ( process . platform === 'darwin' ) {
264276 expect (
265277 Buffer . byteLength ( path . join ( gpgHome , 'S.gpg-agent.browser' ) )
@@ -287,13 +299,18 @@ describe('gpg tests', () => {
287299 'https://example.com/jdk.tar.gz.sig' ,
288300 'public key'
289301 ) ;
290- if ( outcome === 'success' ) {
302+ if ( outcome === 'success' || outcome === 'gpgconf unavailable' ) {
291303 await verification ;
292304 } else {
293305 await expect ( verification ) . rejects . toThrow ( outcome ) ;
294306 }
295307 expect ( exec . exec ) . toHaveBeenCalledTimes (
296- outcome === 'import failure' ? 1 : 2
308+ outcome === 'import failure' ? 2 : 3
309+ ) ;
310+ expect ( exec . exec ) . toHaveBeenLastCalledWith (
311+ 'gpgconf' ,
312+ [ '--homedir' , gpg . toGpgPath ( gpgHome ) , '--kill' , 'gpg-agent' ] ,
313+ { silent : true , ignoreReturnCode : true }
297314 ) ;
298315 expect ( fs . existsSync ( gpgHome ) ) . toBe ( false ) ;
299316 expect ( fs . existsSync ( signaturePath ) ) . toBe ( false ) ;
@@ -368,7 +385,7 @@ describe('gpg tests', () => {
368385 ] ,
369386 expect . objectContaining ( { silent : true } )
370387 ) ;
371- expect ( exec . exec ) . toHaveBeenCalledTimes ( 2 ) ;
388+ expect ( exec . exec ) . toHaveBeenCalledTimes ( 3 ) ;
372389 } ) ;
373390 } ) ;
374391} ) ;
0 commit comments