File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change 1+ import * as exec from "@actions/exec" ;
2+ import { setupKeys , verify , refreshKeys } from "../src/gpg" ;
3+
4+ jest . mock ( "@actions/exec" )
5+
6+ const mockExec = exec . exec as jest . Mock
7+
8+ describe ( "gpg" , ( ) => {
9+
10+ afterEach ( ( ) => {
11+ mockExec . mockClear ( )
12+ } )
13+
14+ it ( 'uses the first responding keyserver in the pool' , async ( ) => {
15+ mockExec . mockImplementation ( ( ) => Promise . resolve ( 0 ) )
16+ await refreshKeys ( )
17+ expect ( mockExec ) . toBeCalledTimes ( 1 )
18+ } )
19+
20+ it ( 'uses the next keyserver in the pool if the previous fails' , async ( ) => {
21+ const failingServers = 3
22+ let testedServers = 0
23+
24+ mockExec . mockImplementation ( ( ) => {
25+ testedServers ++
26+ if ( testedServers >= failingServers ) {
27+ return Promise . resolve ( 0 )
28+ } else {
29+ return Promise . resolve ( 1 )
30+ }
31+ } )
32+
33+ await refreshKeys ( )
34+ expect ( mockExec ) . toBeCalledTimes ( 3 )
35+ } )
36+
37+ it ( 'throws an error if all servers in the pool fails' , async ( ) => {
38+ mockExec . mockImplementation ( ( ) => Promise . resolve ( 1 ) )
39+
40+ try {
41+ await refreshKeys ( )
42+ } catch ( e ) {
43+ expect ( e ) . toEqual ( new Error ( "Failed to refresh keys from any server in the pool." ) ) ;
44+ }
45+ } )
46+
47+ } )
You can’t perform that action at this time.
0 commit comments