Fix functionality / add tests

This commit is contained in:
Philipp Muens 2019-02-27 12:06:08 +01:00
parent 03cc4d4a48
commit 2a075af805
2 changed files with 65 additions and 7 deletions

View File

@ -85,6 +85,9 @@ class AwsCompileSQSEvents {
return EventSourceArn['Fn::GetAtt'][0];
} else if (EventSourceArn['Fn::ImportValue']) {
return EventSourceArn['Fn::ImportValue'];
} else if (EventSourceArn['Fn::Join']) {
// [0] is the used delimiter, [1] is the array with values
return EventSourceArn['Fn::Join'][1].slice(-1).pop();
}
return EventSourceArn.split(':').pop();
}());

View File

@ -391,18 +391,29 @@ describe('AwsCompileSQSEvents', () => {
arn: { 'Fn::ImportValue': 'ForeignQueue' },
},
},
{
sqs: {
arn: {
'Fn::Join': [
':', [
'arn', 'aws', 'sqs', {
Ref: 'AWS::Region',
},
{
Ref: 'AWS::AccountId',
},
'MyQueue',
],
],
},
},
},
],
},
};
awsCompileSQSEvents.compileSQSEvents();
expect(awsCompileSQSEvents.serverless.service
.provider.compiledCloudFormationTemplate.Resources
.FirstEventSourceMappingSQSSomeQueue.Properties.EventSourceArn
).to.deep.equal(
{ 'Fn::GetAtt': ['SomeQueue', 'Arn'] }
);
expect(awsCompileSQSEvents.serverless.service
.provider.compiledCloudFormationTemplate.Resources.IamRoleLambdaExecution
.Properties.Policies[0].PolicyDocument.Statement[0]
@ -424,18 +435,62 @@ describe('AwsCompileSQSEvents', () => {
{
'Fn::ImportValue': 'ForeignQueue',
},
{
'Fn::Join': [
':',
[
'arn',
'aws',
'sqs',
{
Ref: 'AWS::Region',
},
{
Ref: 'AWS::AccountId',
},
'MyQueue',
],
],
},
],
}
);
expect(awsCompileSQSEvents.serverless.service
.provider.compiledCloudFormationTemplate.Resources
.FirstEventSourceMappingSQSSomeQueue.Properties.EventSourceArn
).to.deep.equal(
{ 'Fn::GetAtt': ['SomeQueue', 'Arn'] }
);
expect(awsCompileSQSEvents.serverless.service
.provider.compiledCloudFormationTemplate.Resources
.FirstEventSourceMappingSQSForeignQueue.Properties.EventSourceArn
).to.deep.equal(
{ 'Fn::ImportValue': 'ForeignQueue' }
);
expect(awsCompileSQSEvents.serverless.service
.provider.compiledCloudFormationTemplate.Resources
.FirstEventSourceMappingSQSMyQueue.Properties.EventSourceArn
).to.deep.equal(
{
'Fn::Join': [
':',
[
'arn',
'aws',
'sqs',
{
Ref: 'AWS::Region',
},
{
Ref: 'AWS::AccountId',
},
'MyQueue',
],
],
});
});
it('fails if keys other than Fn::GetAtt/ImportValue are used for dynamic queue ARN', () => {
it('fails if keys other than Fn::GetAtt/ImportValue/Join are used for dynamic ARNs', () => {
awsCompileSQSEvents.serverless.service.functions = {
first: {
events: [