Skip to content

Commit

Permalink
KeyToolSpec now uses MockLog (#291)
Browse files Browse the repository at this point in the history
* KeyToolSpec now uses MockLog

* Changed the initialization of the MockLogs into Keytoll's initialization.

* Removed redundant import line
  • Loading branch information
chenlevy24 authored Aug 19, 2020
1 parent e27197f commit 38a7ef1
Showing 1 changed file with 6 additions and 5 deletions.
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

0 comments on commit 38a7ef1

Please sign in to comment.