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