From 28be2caaa15ca099893a61827a4b045b6a96b948 Mon Sep 17 00:00:00 2001 From: Chen Levy Date: Wed, 19 Aug 2020 08:05:44 +0000 Subject: [PATCH 1/3] KeyToolSpec now uses MockLog --- packages/core/src/spec/lib/jdk/KeyToolSpec.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/core/src/spec/lib/jdk/KeyToolSpec.ts b/packages/core/src/spec/lib/jdk/KeyToolSpec.ts index 8225f915..92e08db0 100644 --- a/packages/core/src/spec/lib/jdk/KeyToolSpec.ts +++ b/packages/core/src/spec/lib/jdk/KeyToolSpec.ts @@ -19,6 +19,8 @@ import {Config} from '../../../lib/Config'; import util = require('../../../lib/util'); import {JdkHelper} from '../../../lib/jdk/JdkHelper'; import * as fs from 'fs'; +import {MockLog} from '../../..'; +import mock = require('mock-fs'); 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:' + @@ -64,7 +66,8 @@ describe('KeyTool', () => { } as CreateKeyOptions; it('Executes the correct command to create a key', async () => { - const keyTool = new KeyTool(jdkHelper); + const mockLog = new MockLog(); + const keyTool = new KeyTool(jdkHelper, mockLog); spyOn(fs, 'existsSync').and.returnValue(false); spyOn(util, 'execute').and.stub(); await keyTool.createSigningKey(keyOptions); @@ -83,7 +86,8 @@ describe('KeyTool', () => { }); it('Skips creation when a key already exists', async () => { - const keyTool = new KeyTool(jdkHelper); + const mockLog = new MockLog(); + const keyTool = new KeyTool(jdkHelper, mockLog); spyOn(fs, 'existsSync').and.returnValue(true); spyOn(util, 'execute').and.stub(); await keyTool.createSigningKey(keyOptions); @@ -91,7 +95,8 @@ describe('KeyTool', () => { }); it('Deletes and writes a new key when overwrite = true', async () => { - const keyTool = new KeyTool(jdkHelper); + const mockLog = new MockLog(); + const keyTool = new KeyTool(jdkHelper, mockLog); spyOn(fs, 'existsSync').and.returnValue(true); spyOn(fs.promises, 'unlink').and.resolveTo(); spyOn(util, 'execute').and.stub(); @@ -126,7 +131,8 @@ describe('KeyTool', () => { }); it('Throws error if keyOptions.path doesn\'t exist', async () => { - const keyTool = new KeyTool(jdkHelper); + const mockLog = new MockLog(); + const keyTool = new KeyTool(jdkHelper, mockLog); spyOn(fs, 'existsSync').and.returnValue(false); expectAsync(keyTool.list(keyOptions)).toBeRejectedWithError(); }); From 6d64b458820fb6ad58c1da272ee929f0768a345f Mon Sep 17 00:00:00 2001 From: Chen Levy Date: Wed, 19 Aug 2020 08:19:31 +0000 Subject: [PATCH 2/3] Changed the initialization of the MockLogs into Keytoll's initialization. --- packages/core/src/spec/lib/jdk/KeyToolSpec.ts | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/packages/core/src/spec/lib/jdk/KeyToolSpec.ts b/packages/core/src/spec/lib/jdk/KeyToolSpec.ts index 92e08db0..a9042b26 100644 --- a/packages/core/src/spec/lib/jdk/KeyToolSpec.ts +++ b/packages/core/src/spec/lib/jdk/KeyToolSpec.ts @@ -66,8 +66,7 @@ describe('KeyTool', () => { } as CreateKeyOptions; it('Executes the correct command to create a key', async () => { - const mockLog = new MockLog(); - const keyTool = new KeyTool(jdkHelper, mockLog); + const keyTool = new KeyTool(jdkHelper, new MockLog()); spyOn(fs, 'existsSync').and.returnValue(false); spyOn(util, 'execute').and.stub(); await keyTool.createSigningKey(keyOptions); @@ -86,8 +85,7 @@ describe('KeyTool', () => { }); it('Skips creation when a key already exists', async () => { - const mockLog = new MockLog(); - const keyTool = new KeyTool(jdkHelper, mockLog); + const keyTool = new KeyTool(jdkHelper, new MockLog()); spyOn(fs, 'existsSync').and.returnValue(true); spyOn(util, 'execute').and.stub(); await keyTool.createSigningKey(keyOptions); @@ -95,8 +93,7 @@ describe('KeyTool', () => { }); it('Deletes and writes a new key when overwrite = true', async () => { - const mockLog = new MockLog(); - const keyTool = new KeyTool(jdkHelper, mockLog); + const keyTool = new KeyTool(jdkHelper, new MockLog()); spyOn(fs, 'existsSync').and.returnValue(true); spyOn(fs.promises, 'unlink').and.resolveTo(); spyOn(util, 'execute').and.stub(); @@ -115,7 +112,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); @@ -131,8 +128,7 @@ describe('KeyTool', () => { }); it('Throws error if keyOptions.path doesn\'t exist', async () => { - const mockLog = new MockLog(); - const keyTool = new KeyTool(jdkHelper, mockLog); + const keyTool = new KeyTool(jdkHelper, new MockLog()); spyOn(fs, 'existsSync').and.returnValue(false); expectAsync(keyTool.list(keyOptions)).toBeRejectedWithError(); }); From d9d07124eba8ba9a348c35d2bcb91373de5509b1 Mon Sep 17 00:00:00 2001 From: Chen Levy Date: Wed, 19 Aug 2020 08:24:44 +0000 Subject: [PATCH 3/3] Removed redundant import line --- packages/core/src/spec/lib/jdk/KeyToolSpec.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/core/src/spec/lib/jdk/KeyToolSpec.ts b/packages/core/src/spec/lib/jdk/KeyToolSpec.ts index a9042b26..39cbed9c 100644 --- a/packages/core/src/spec/lib/jdk/KeyToolSpec.ts +++ b/packages/core/src/spec/lib/jdk/KeyToolSpec.ts @@ -20,7 +20,6 @@ import util = require('../../../lib/util'); import {JdkHelper} from '../../../lib/jdk/JdkHelper'; import * as fs from 'fs'; import {MockLog} from '../../..'; -import mock = require('mock-fs'); 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:' +