/
private-key.spec.ts
43 lines (37 loc) · 1.41 KB
/
private-key.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { Fixtures } from '../../../test/fixtures';
import { mocked } from '../../../test/util';
import * as exec_ from '../exec';
import { configSigningKey, writePrivateKey } from './private-key';
import { setPrivateKey } from '.';
jest.mock('fs-extra', () => Fixtures.fsExtra());
jest.mock('../exec');
const exec = mocked(exec_);
describe('util/git/private-key', () => {
describe('writePrivateKey()', () => {
it('returns if no private key', async () => {
await expect(writePrivateKey()).resolves.not.toThrow();
await expect(configSigningKey('/tmp/some-repo')).resolves.not.toThrow();
});
it('throws error if failing', async () => {
setPrivateKey('some-key');
exec.exec.mockRejectedValueOnce({
stderr: `something wrong`,
stdout: '',
});
await expect(writePrivateKey()).rejects.toThrow();
});
it('imports the private key', async () => {
setPrivateKey('some-key');
exec.exec.mockResolvedValueOnce({
stderr: `gpg: key BADC0FFEE: secret key imported\nfoo\n`,
stdout: '',
});
await expect(writePrivateKey()).resolves.not.toThrow();
await expect(configSigningKey('/tmp/some-repo')).resolves.not.toThrow();
});
it('does not import the key again', async () => {
await expect(writePrivateKey()).resolves.not.toThrow();
await expect(configSigningKey('/tmp/some-repo')).resolves.not.toThrow();
});
});
});