renovate/lib/util/git/private-key.spec.ts
2020-07-03 16:47:00 +02:00

35 lines
1.1 KiB
TypeScript

import { getName, mocked } from '../../../test/util';
import * as exec_ from '../exec';
import { setPrivateKey, writePrivateKey } from './private-key';
jest.mock('fs-extra');
jest.mock('../exec');
const exec = mocked(exec_);
describe(getName(__filename), () => {
describe('writePrivateKey()', () => {
it('returns if no private key', async () => {
await expect(writePrivateKey('/tmp/some-repo')).resolves.not.toThrow();
});
it('throws error if failing', async () => {
setPrivateKey('some-key');
exec.exec.mockResolvedValueOnce({
stderr: `something wrong`,
stdout: '',
});
await expect(writePrivateKey('/tmp/some-repo')).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('/tmp/some-repo')).resolves.not.toThrow();
});
it('does not import the key again', async () => {
await expect(writePrivateKey('/tmp/some-repo')).resolves.not.toThrow();
});
});
});