From 278af3c64fb74b71a0a5888ba1156446a9903b8e Mon Sep 17 00:00:00 2001 From: bitrinjani Date: Sat, 30 Dec 2017 08:19:09 +0900 Subject: [PATCH] add unit test for MaxTargetVolumeLimit --- src/__tests__/LimitCheckerImpl.test.ts | 38 ++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/__tests__/LimitCheckerImpl.test.ts diff --git a/src/__tests__/LimitCheckerImpl.test.ts b/src/__tests__/LimitCheckerImpl.test.ts new file mode 100644 index 00000000..b601fad8 --- /dev/null +++ b/src/__tests__/LimitCheckerImpl.test.ts @@ -0,0 +1,38 @@ +import LimitCheckerImpl from '../LimitCheckerImpl'; +import { options } from '../logger'; +options.enabled = false; + +describe('LimitCheckerImpl', () => { + test('MaxTargetVolumeLimit - violate', () => { + const config = { maxTargetVolumePercent: 50 }; + const ps = {}; + const analysisResult = { availableVolume: 1.0, targetVolume: 0.7 }; + const checker = new LimitCheckerImpl({ config }, ps, analysisResult, analysisResult, false); + checker.limits = checker.limits.filter(limit => limit.constructor.name === 'MaxTargetVolumeLimit'); + const result = checker.check(); + expect(result.success).toBe(false); + expect(result.reason).toBe('Too large Volume'); + }); + + test('MaxTargetVolumeLimit - pass', () => { + const config = { maxTargetVolumePercent: 50 }; + const ps = {}; + const analysisResult = { availableVolume: 1.0, targetVolume: 0.3 }; + const checker = new LimitCheckerImpl({ config }, ps, analysisResult, analysisResult, false); + checker.limits = checker.limits.filter(limit => limit.constructor.name === 'MaxTargetVolumeLimit'); + const result = checker.check(); + expect(result.success).toBe(true); + expect(result.reason).toBe(''); + }); + + test('MaxTargetVolumeLimit - undefined', () => { + const config = { maxTargetVolumePercent: undefined }; + const ps = {}; + const analysisResult = { availableVolume: 1.0, targetVolume: 0.3 }; + const checker = new LimitCheckerImpl({ config }, ps, analysisResult, analysisResult, false); + checker.limits = checker.limits.filter(limit => limit.constructor.name === 'MaxTargetVolumeLimit'); + const result = checker.check(); + expect(result.success).toBe(true); + expect(result.reason).toBe(''); + }); +});