Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyToolSpec now uses MockLog #291

Merged
merged 3 commits into from
Aug 19, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions packages/core/src/spec/lib/jdk/KeyToolSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {Config} from '../../../lib/Config';
import util = require('../../../lib/util');
import {JdkHelper} from '../../../lib/jdk/JdkHelper';
import * as fs from 'fs';
import {MockLog} from '../../..';

const SHA1 = '38:03:D6:95:91:7C:9C:EE:4A:A0:58:43:A7:43:A5:D2:76:52:EF:9B';
const SHA256 = 'F5:08:9F:8A:D4:C8:4A:15:6D:0A:B1:3F:61:96:BE:C7:87:8C:DE:05:59:92:B2:A3:2D:05:' +
Expand Down Expand Up @@ -64,7 +65,7 @@ describe('KeyTool', () => {
} as CreateKeyOptions;

it('Executes the correct command to create a key', async () => {
const keyTool = new KeyTool(jdkHelper);
const keyTool = new KeyTool(jdkHelper, new MockLog());
spyOn(fs, 'existsSync').and.returnValue(false);
spyOn(util, 'execute').and.stub();
await keyTool.createSigningKey(keyOptions);
Expand All @@ -83,15 +84,15 @@ describe('KeyTool', () => {
});

it('Skips creation when a key already exists', async () => {
const keyTool = new KeyTool(jdkHelper);
const keyTool = new KeyTool(jdkHelper, new MockLog());
spyOn(fs, 'existsSync').and.returnValue(true);
spyOn(util, 'execute').and.stub();
await keyTool.createSigningKey(keyOptions);
expect(util.execute).not.toHaveBeenCalled();
});

it('Deletes and writes a new key when overwrite = true', async () => {
const keyTool = new KeyTool(jdkHelper);
const keyTool = new KeyTool(jdkHelper, new MockLog());
spyOn(fs, 'existsSync').and.returnValue(true);
spyOn(fs.promises, 'unlink').and.resolveTo();
spyOn(util, 'execute').and.stub();
Expand All @@ -110,7 +111,7 @@ describe('KeyTool', () => {
} as KeyOptions;

it('Executes the correct command to list keys', async () => {
const keyTool = new KeyTool(jdkHelper);
const keyTool = new KeyTool(jdkHelper, new MockLog());
spyOn(fs, 'existsSync').and.returnValue(true);
spyOn(util, 'execute').and.resolveTo({stdout: '', stderr: ''});
await keyTool.list(keyOptions);
Expand All @@ -126,7 +127,7 @@ describe('KeyTool', () => {
});

it('Throws error if keyOptions.path doesn\'t exist', async () => {
const keyTool = new KeyTool(jdkHelper);
const keyTool = new KeyTool(jdkHelper, new MockLog());
spyOn(fs, 'existsSync').and.returnValue(false);
expectAsync(keyTool.list(keyOptions)).toBeRejectedWithError();
});
Expand Down