|
2 | 2 |
|
3 | 3 | const _ = require('lodash');
|
4 | 4 | const expect = require('chai').expect;
|
| 5 | +const sinon = require('sinon'); |
5 | 6 | const Serverless = require('serverless/lib/Serverless');
|
6 | 7 | const AwsProvider = require('serverless/lib/plugins/aws/provider/awsProvider');
|
7 | 8 | const ServerlessStepFunctions = require('./../../index');
|
8 | 9 |
|
9 | 10 | describe('#compileAlarms', () => {
|
| 11 | + let consoleLogSpy; |
10 | 12 | let serverless;
|
11 | 13 | let serverlessStepFunctions;
|
12 | 14 |
|
13 | 15 | beforeEach(() => {
|
| 16 | + consoleLogSpy = sinon.spy(); |
14 | 17 | serverless = new Serverless();
|
15 | 18 | serverless.servicePath = true;
|
16 | 19 | serverless.service.service = 'step-functions';
|
17 | 20 | serverless.service.provider.compiledCloudFormationTemplate = { Resources: {} };
|
18 | 21 | serverless.setProvider('aws', new AwsProvider(serverless));
|
19 |
| - serverless.cli = { consoleLog: console.log }; |
| 22 | + serverless.cli = { consoleLog: consoleLogSpy }; |
20 | 23 | const options = {
|
21 | 24 | stage: 'dev',
|
22 | 25 | region: 'ap-northeast-1',
|
@@ -87,6 +90,37 @@ describe('#compileAlarms', () => {
|
87 | 90 | validateCloudWatchAlarm(resources.StateMachineBeta2ExecutionsAbortedAlarm);
|
88 | 91 | expect(resources).to.have.property('StateMachineBeta2ExecutionThrottledAlarm');
|
89 | 92 | validateCloudWatchAlarm(resources.StateMachineBeta2ExecutionThrottledAlarm);
|
| 93 | + |
| 94 | + expect(consoleLogSpy.callCount).equal(0); |
| 95 | + }); |
| 96 | + |
| 97 | + it('should not generate logs when no CloudWatch Alarms are defiened', () => { |
| 98 | + const genStateMachine = (name) => ({ |
| 99 | + name, |
| 100 | + definition: { |
| 101 | + StartAt: 'A', |
| 102 | + States: { |
| 103 | + A: { |
| 104 | + Type: 'Pass', |
| 105 | + End: true, |
| 106 | + }, |
| 107 | + }, |
| 108 | + }, |
| 109 | + }); |
| 110 | + |
| 111 | + serverless.service.stepFunctions = { |
| 112 | + stateMachines: { |
| 113 | + myStateMachine1: genStateMachine('stateMachineBeta1'), |
| 114 | + myStateMachine2: genStateMachine('stateMachineBeta2'), |
| 115 | + }, |
| 116 | + }; |
| 117 | + |
| 118 | + serverlessStepFunctions.compileAlarms(); |
| 119 | + const resources = serverlessStepFunctions.serverless.service |
| 120 | + .provider.compiledCloudFormationTemplate.Resources; |
| 121 | + expect(_.keys(resources)).to.have.lengthOf(0); |
| 122 | + |
| 123 | + expect(consoleLogSpy.callCount).equal(0); |
90 | 124 | });
|
91 | 125 |
|
92 | 126 | it('should not generate CloudWatch Alarms when alarms.topics is missing', () => {
|
@@ -119,6 +153,8 @@ describe('#compileAlarms', () => {
|
119 | 153 | const resources = serverlessStepFunctions.serverless.service
|
120 | 154 | .provider.compiledCloudFormationTemplate.Resources;
|
121 | 155 | expect(_.keys(resources)).to.have.lengthOf(0);
|
| 156 | + |
| 157 | + expect(consoleLogSpy.callCount).equal(2); |
122 | 158 | });
|
123 | 159 |
|
124 | 160 | it('should not generate CloudWatch Alarms when alarms.topics is empty', () => {
|
@@ -152,6 +188,8 @@ describe('#compileAlarms', () => {
|
152 | 188 | const resources = serverlessStepFunctions.serverless.service
|
153 | 189 | .provider.compiledCloudFormationTemplate.Resources;
|
154 | 190 | expect(_.keys(resources)).to.have.lengthOf(0);
|
| 191 | + |
| 192 | + expect(consoleLogSpy.callCount).equal(2); |
155 | 193 | });
|
156 | 194 |
|
157 | 195 | it('should not generate CloudWatch Alarms when alarms.metrics is missing', () => {
|
@@ -184,6 +222,8 @@ describe('#compileAlarms', () => {
|
184 | 222 | const resources = serverlessStepFunctions.serverless.service
|
185 | 223 | .provider.compiledCloudFormationTemplate.Resources;
|
186 | 224 | expect(_.keys(resources)).to.have.lengthOf(0);
|
| 225 | + |
| 226 | + expect(consoleLogSpy.callCount).equal(2); |
187 | 227 | });
|
188 | 228 |
|
189 | 229 | it('should not generate CloudWatch Alarms for unsupported metrics', () => {
|
@@ -225,5 +265,7 @@ describe('#compileAlarms', () => {
|
225 | 265 |
|
226 | 266 | // but invalid metric names are skipped
|
227 | 267 | expect(_.keys(resources)).to.have.lengthOf(2);
|
| 268 | + |
| 269 | + expect(consoleLogSpy.callCount).equal(2); |
228 | 270 | });
|
229 | 271 | });
|
0 commit comments