@@ -97,6 +97,9 @@ const _mockSetting = () => {
9797 awsMock . mock ( 'CloudWatchLogs' , 'putRetentionPolicy' , ( params , callback ) => {
9898 callback ( null , { } )
9999 } )
100+ awsMock . mock ( 'S3' , 'putBucketNotificationConfiguration' , ( params , callback ) => {
101+ callback ( null , { } )
102+ } )
100103
101104 Object . keys ( lambdaMockSettings ) . forEach ( ( method ) => {
102105 awsMock . mock ( 'Lambda' , method , ( params , callback ) => {
@@ -110,6 +113,7 @@ const _mockSetting = () => {
110113const _awsRestore = ( ) => {
111114 awsMock . restore ( 'CloudWatchEvents' )
112115 awsMock . restore ( 'CloudWatchLogs' )
116+ awsMock . restore ( 'S3' )
113117 awsMock . restore ( 'Lambda' )
114118}
115119
@@ -781,7 +785,11 @@ describe('lib/main', function () {
781785 program . eventSourceFile = ''
782786 assert . deepEqual (
783787 lambda . _eventSourceList ( program ) ,
784- { EventSourceMappings : null , ScheduleEvents : null }
788+ {
789+ EventSourceMappings : null ,
790+ ScheduleEvents : null ,
791+ S3Events : null
792+ }
785793 )
786794 } )
787795
@@ -803,18 +811,23 @@ describe('lib/main', function () {
803811 fs . writeFileSync ( 'only_ScheduleEvents.json' , JSON . stringify ( {
804812 ScheduleEvents : [ { test : 2 } ]
805813 } ) )
814+ fs . writeFileSync ( 'only_S3Events.json' , JSON . stringify ( {
815+ S3Events : [ { test : 3 } ]
816+ } ) )
806817 } )
807818
808819 after ( ( ) => {
809820 fs . unlinkSync ( 'only_EventSourceMappings.json' )
810821 fs . unlinkSync ( 'only_ScheduleEvents.json' )
822+ fs . unlinkSync ( 'only_S3Events.json' )
811823 } )
812824
813825 it ( 'only EventSourceMappings' , ( ) => {
814826 program . eventSourceFile = 'only_EventSourceMappings.json'
815827 const expected = {
816828 EventSourceMappings : [ { test : 1 } ] ,
817- ScheduleEvents : [ ]
829+ ScheduleEvents : [ ] ,
830+ S3Events : [ ]
818831 }
819832 assert . deepEqual ( lambda . _eventSourceList ( program ) , expected )
820833 } )
@@ -823,7 +836,18 @@ describe('lib/main', function () {
823836 program . eventSourceFile = 'only_ScheduleEvents.json'
824837 const expected = {
825838 EventSourceMappings : [ ] ,
826- ScheduleEvents : [ { test : 2 } ]
839+ ScheduleEvents : [ { test : 2 } ] ,
840+ S3Events : [ ]
841+ }
842+ assert . deepEqual ( lambda . _eventSourceList ( program ) , expected )
843+ } )
844+
845+ it ( 'only S3Events' , ( ) => {
846+ program . eventSourceFile = 'only_S3Events.json'
847+ const expected = {
848+ EventSourceMappings : [ ] ,
849+ ScheduleEvents : [ ] ,
850+ S3Events : [ { test : 3 } ]
827851 }
828852 assert . deepEqual ( lambda . _eventSourceList ( program ) , expected )
829853 } )
@@ -845,6 +869,20 @@ describe('lib/main', function () {
845869 key1 : 'value' ,
846870 key2 : 'value'
847871 }
872+ } ] ,
873+ S3Events : [ {
874+ Bucket : 'BUCKET_NAME' ,
875+ Events : [
876+ 's3:ObjectCreated:*'
877+ ] ,
878+ Filter : {
879+ Key : {
880+ FilterRules : [ {
881+ Name : 'prefix' ,
882+ Value : 'STRING_VALUE'
883+ } ]
884+ }
885+ }
848886 } ]
849887 }
850888 assert . deepEqual ( lambda . _eventSourceList ( program ) , expected )
@@ -867,7 +905,8 @@ describe('lib/main', function () {
867905 program . eventSourceFile = fileName
868906 const expected = {
869907 EventSourceMappings : oldStyleValue ,
870- ScheduleEvents : [ ]
908+ ScheduleEvents : [ ] ,
909+ S3Events : [ ]
871910 }
872911 assert . deepEqual ( lambda . _eventSourceList ( program ) , expected )
873912 } )
@@ -1015,6 +1054,58 @@ describe('lib/main', function () {
10151054 } )
10161055 } )
10171056
1057+ describe ( '_updateS3Events' , ( ) => {
1058+ const S3Events = require ( path . join ( '..' , 'lib' , 's3_events' ) )
1059+ const eventSourcesJsonValue = {
1060+ S3Events : [ {
1061+ Bucket : 'node-lambda-test-bucket' ,
1062+ Events : [ 's3:ObjectCreated:*' ] ,
1063+ Filter : null
1064+ } ]
1065+ }
1066+
1067+ let s3Events = null
1068+
1069+ before ( ( ) => {
1070+ fs . writeFileSync (
1071+ 'event_sources.json' ,
1072+ JSON . stringify ( eventSourcesJsonValue )
1073+ )
1074+ s3Events = new S3Events ( aws )
1075+ } )
1076+
1077+ after ( ( ) => fs . unlinkSync ( 'event_sources.json' ) )
1078+
1079+ it ( 'program.eventSourceFile is empty value' , ( ) => {
1080+ program . eventSourceFile = ''
1081+ const eventSourceList = lambda . _eventSourceList ( program )
1082+ return lambda . _updateS3Events (
1083+ s3Events ,
1084+ '' ,
1085+ eventSourceList . S3Events
1086+ ) . then ( results => {
1087+ assert . deepEqual ( results , [ ] )
1088+ } )
1089+ } )
1090+
1091+ it ( 'simple test with mock' , ( ) => {
1092+ program . eventSourceFile = 'event_sources.json'
1093+ const eventSourceList = lambda . _eventSourceList ( program )
1094+ const functionArn = 'arn:aws:lambda:us-west-2:XXX:function:node-lambda-test-function'
1095+ return lambda . _updateS3Events (
1096+ s3Events ,
1097+ functionArn ,
1098+ eventSourceList . S3Events
1099+ ) . then ( results => {
1100+ const expected = [ Object . assign (
1101+ eventSourcesJsonValue . S3Events [ 0 ] ,
1102+ { FunctionArn : functionArn }
1103+ ) ]
1104+ assert . deepEqual ( results , expected )
1105+ } )
1106+ } )
1107+ } )
1108+
10181109 describe ( '_uploadNew' , ( ) => {
10191110 it ( 'simple test with mock' , ( ) => {
10201111 const params = lambda . _params ( program , null )
0 commit comments