@@ -2,7 +2,7 @@ import 'mocha';
22import { expect } from 'chai' ;
33import sinon from 'sinon' ;
44
5- import { initialize } from '../../../src' ;
5+ import { initialize , initializeFrom } from '../../../src' ;
66
77import { fromAlarm } from '../../../src/from/cw' ;
88
@@ -125,4 +125,85 @@ describe('flavors/circuitbreaker.js', () => {
125125 } )
126126 . done ( done ) ;
127127 } ) ;
128+
129+ it ( 'should enable event source mapping with batch size from opt)' , ( done ) => {
130+ const rules = [
131+ {
132+ id : 'circuitBreaker' ,
133+ flavor : circuitBreaker ,
134+ circuitBreakerMaxBatchSize : '10' ,
135+ } ,
136+ ] ;
137+ const event = {
138+ source : 'aws.cloudwatch' ,
139+ alarmArn :
140+ 'arn:aws:cloudwatch:us-east-1:444455556666:alarm:lambda-demo-metric-alarm' ,
141+ accountId : '444455556666' ,
142+ time : '2023-08-04T12:36:15.490+0000' ,
143+ region : 'us-east-1' ,
144+ alarmData : {
145+ alarmName : 'lambda-demo-metric-alarm' ,
146+ state : {
147+ value : 'OK' ,
148+ } ,
149+ previousState : {
150+ value : 'INSUFFICIENT_DATA' ,
151+ } ,
152+ } ,
153+ } ;
154+
155+ initialize ( {
156+ ...initializeFrom ( rules ) ,
157+ } )
158+ . assemble ( fromAlarm ( event ) , false )
159+ . collect ( )
160+ // .tap((collected) => console.log(JSON.stringify(collected, null, 2)))
161+ . tap ( ( collected ) => {
162+ expect ( collected . length ) . to . equal ( 1 ) ;
163+ expect ( collected [ 0 ] . pipeline ) . to . equal ( 'circuitBreaker' ) ;
164+ expect ( collected [ 0 ] . updateRequest ) . to . deep . equal ( {
165+ UUID : 'a092f90d-9948-4964-95b5-32c46093f734' ,
166+ Enabled : true ,
167+ BatchSize : 10 ,
168+ } ) ;
169+ } )
170+ . done ( done ) ;
171+ } ) ;
172+ it ( 'should enable event source mapping and force Number type for env var of CIRCUIT_BREAKER_MAX_BATCH_SIZE' , ( done ) => {
173+ process . env . CIRCUIT_BREAKER_MAX_BATCH_SIZE = '10' ;
174+ const event = {
175+ source : 'aws.cloudwatch' ,
176+ alarmArn :
177+ 'arn:aws:cloudwatch:us-east-1:444455556666:alarm:lambda-demo-metric-alarm' ,
178+ accountId : '444455556666' ,
179+ time : '2023-08-04T12:36:15.490+0000' ,
180+ region : 'us-east-1' ,
181+ alarmData : {
182+ alarmName : 'lambda-demo-metric-alarm' ,
183+ state : {
184+ value : 'OK' ,
185+ } ,
186+ previousState : {
187+ value : 'INSUFFICIENT_DATA' ,
188+ } ,
189+ } ,
190+ } ;
191+
192+ initialize ( {
193+ circuitBreaker,
194+ } )
195+ . assemble ( fromAlarm ( event ) , false )
196+ . collect ( )
197+ // .tap((collected) => console.log(JSON.stringify(collected, null, 2)))
198+ . tap ( ( collected ) => {
199+ expect ( collected . length ) . to . equal ( 1 ) ;
200+ expect ( collected [ 0 ] . pipeline ) . to . equal ( 'circuitBreaker' ) ;
201+ expect ( collected [ 0 ] . updateRequest ) . to . deep . equal ( {
202+ UUID : 'a092f90d-9948-4964-95b5-32c46093f734' ,
203+ Enabled : true ,
204+ BatchSize : 10 ,
205+ } ) ;
206+ } )
207+ . done ( done ) ;
208+ } ) ;
128209} ) ;
0 commit comments