@@ -507,18 +507,10 @@ describe('node-lambda', function () {
507507 describe ( '_eventSourceList' , function ( ) {
508508 it ( 'program.eventSourceFile is empty value' , function ( ) {
509509 program . eventSourceFile = '' ;
510- assert . deepEqual ( lambda . _eventSourceList ( program ) , [ ] ) ;
511- } ) ;
512-
513- it ( 'program.eventSourceFile is valid value' , function ( ) {
514- program . eventSourceFile = 'event_sources.json' ;
515- const expected = [ {
516- BatchSize : 100 ,
517- Enabled : true ,
518- EventSourceArn : 'your event source arn' ,
519- StartingPosition : 'LATEST' ,
520- } ] ;
521- assert . deepEqual ( lambda . _eventSourceList ( program ) , expected ) ;
510+ assert . deepEqual (
511+ lambda . _eventSourceList ( program ) ,
512+ { EventSourceMappings : [ ] , ScheduleEvents : [ ] }
513+ ) ;
522514 } ) ;
523515
524516 it ( 'program.eventSourceFile is invalid value' , function ( ) {
@@ -529,6 +521,83 @@ describe('node-lambda', function () {
529521 "ENOENT: no such file or directory, open '/hoge/fuga'"
530522 ) ;
531523 } ) ;
524+
525+ describe ( 'program.eventSourceFile is valid value' , function ( ) {
526+ before ( function ( ) {
527+ fs . writeFileSync ( 'only_EventSourceMappings.json' , JSON . stringify ( {
528+ EventSourceMappings : [ { test : 1 } ]
529+ } ) ) ;
530+ fs . writeFileSync ( 'only_ScheduleEvents.json' , JSON . stringify ( {
531+ ScheduleEvents : [ { test : 2 } ]
532+ } ) ) ;
533+ } ) ;
534+
535+ after ( function ( ) {
536+ fs . unlinkSync ( 'only_EventSourceMappings.json' ) ;
537+ fs . unlinkSync ( 'only_ScheduleEvents.json' ) ;
538+ } ) ;
539+
540+ it ( 'only EventSourceMappings' , function ( ) {
541+ program . eventSourceFile = 'only_EventSourceMappings.json' ;
542+ const expected = {
543+ EventSourceMappings : [ { test : 1 } ] ,
544+ ScheduleEvents : [ ] ,
545+ } ;
546+ assert . deepEqual ( lambda . _eventSourceList ( program ) , expected ) ;
547+ } ) ;
548+
549+ it ( 'only ScheduleEvents' , function ( ) {
550+ program . eventSourceFile = 'only_ScheduleEvents.json' ;
551+ const expected = {
552+ EventSourceMappings : [ ] ,
553+ ScheduleEvents : [ { test : 2 } ] ,
554+ } ;
555+ assert . deepEqual ( lambda . _eventSourceList ( program ) , expected ) ;
556+ } ) ;
557+
558+ it ( 'EventSourceMappings & ScheduleEvents' , function ( ) {
559+ program . eventSourceFile = 'event_sources.json' ;
560+ const expected = {
561+ EventSourceMappings : [ {
562+ BatchSize : 100 ,
563+ Enabled : true ,
564+ EventSourceArn : 'your event source arn' ,
565+ StartingPosition : 'LATEST' ,
566+ } ] ,
567+ ScheduleEvents : [ {
568+ FunctionArnPrefix : 'arn:aws:lambda:us-west-2:XXX:function:' ,
569+ ScheduleName : 'node-lambda-test-schedule' ,
570+ ScheduleState : 'ENABLED' ,
571+ ScheduleExpression : 'rate(1 hour)' ,
572+ } ] ,
573+ } ;
574+ assert . deepEqual ( lambda . _eventSourceList ( program ) , expected ) ;
575+ } ) ;
576+ } ) ;
577+
578+ describe ( 'old style event_sources.json' , function ( ) {
579+ const oldStyleValue = [ {
580+ BatchSize : 100 ,
581+ Enabled : true ,
582+ EventSourceArn : 'your event source arn' ,
583+ StartingPosition : 'LATEST' ,
584+ } ] ;
585+ const fileName = 'event_sources_old_style.json' ;
586+
587+ before ( function ( ) {
588+ fs . writeFileSync ( fileName , JSON . stringify ( oldStyleValue ) ) ;
589+ } ) ;
590+
591+ after ( function ( ) {
592+ fs . unlinkSync ( fileName ) ;
593+ } ) ;
594+
595+ it ( 'program.eventSourceFile is valid value' , function ( ) {
596+ program . eventSourceFile = fileName ;
597+ const expected = { EventSourceMappings : oldStyleValue } ;
598+ assert . deepEqual ( lambda . _eventSourceList ( program ) , expected ) ;
599+ } ) ;
600+ } ) ;
532601 } ) ;
533602 } ) ;
534603
0 commit comments